blob: e14f6f8a13ecdb8bb35b09a4d554de88fe9144db [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes3f981df2012-03-27 18:59:44 -04002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000016import copy
Doug Hellmann583ce2c2015-03-11 14:55:46 +000017from oslo_log import log as logging
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000018from tempest.common import negative_rest_client
Jay Pipesf38eaac2012-06-21 13:37:35 -040019from tempest import config
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +010020from tempest import exceptions
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010021from tempest.lib import auth
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010022from tempest.lib import exceptions as lib_exc
Andrea Frittoli (andreaf)e07579c2016-08-05 07:27:02 +010023from tempest.lib.services import clients
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010024from tempest.services import baremetal
25from tempest.services import data_processing
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +010026from tempest.services import identity
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +010027from tempest.services import object_storage
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010028from tempest.services import orchestration
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +010029from tempest.services import volume
Vincent Hou6b8a7b72012-08-25 01:24:33 +080030
Sean Dague86bd8422013-12-20 09:56:44 -050031CONF = config.CONF
Jay Pipes3f981df2012-03-27 18:59:44 -040032LOG = logging.getLogger(__name__)
33
Vincent Hou6b8a7b72012-08-25 01:24:33 +080034
Andrea Frittoli (andreaf)e07579c2016-08-05 07:27:02 +010035class Manager(clients.ServiceClients):
Ken'ichi Ohmichi2e2ee192015-11-19 09:48:27 +000036 """Top level manager for OpenStack tempest clients"""
Jay Pipes3f981df2012-03-27 18:59:44 -040037
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010038 default_params = config.service_client_config()
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000039
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010040 # TODO(andreaf) This is only used by data_processing and baremetal clients,
41 # and should be removed once they are out of Tempest
Ken'ichi Ohmichi737a6032015-01-21 07:04:42 +000042 default_params_with_timeout_values = {
43 'build_interval': CONF.compute.build_interval,
44 'build_timeout': CONF.compute.build_timeout
45 }
46 default_params_with_timeout_values.update(default_params)
47
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010048 def __init__(self, credentials, service=None, scope='project'):
ghanshyam4e2be342015-11-27 18:07:46 +090049 """Initialization of Manager class.
Brant Knudsonc7ca3342013-03-28 21:08:50 -050050
ghanshyam4e2be342015-11-27 18:07:46 +090051 Setup all services clients and make them available for tests cases.
52 :param credentials: type Credentials or TestResources
53 :param service: Service name
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010054 :param scope: default scope for tokens produced by the auth provider
ghanshyam4e2be342015-11-27 18:07:46 +090055 """
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010056 _, identity_uri = get_auth_provider_class(credentials)
57 super(Manager, self).__init__(
58 credentials=credentials, identity_uri=identity_uri, scope=scope,
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010059 region=CONF.identity.region,
60 client_parameters=self._prepare_configuration())
61 # TODO(andreaf) When clients are initialised without the right
62 # parameters available, the calls below will trigger a KeyError.
63 # We should catch that and raise a better error.
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +000064 self._set_compute_clients()
65 self._set_identity_clients()
66 self._set_volume_clients()
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +000067 self._set_object_storage_clients()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010068 self._set_image_clients()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010069 self._set_network_clients()
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +000070
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010071 self.baremetal_client = baremetal.BaremetalClient(
Ken'ichi Ohmichi1f88ece2015-01-23 03:33:11 +000072 self.auth_provider,
73 CONF.baremetal.catalog_type,
74 CONF.identity.region,
75 endpoint_type=CONF.baremetal.endpoint_type,
76 **self.default_params_with_timeout_values)
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010077 self.orchestration_client = orchestration.OrchestrationClient(
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000078 self.auth_provider,
79 CONF.orchestration.catalog_type,
80 CONF.orchestration.region or CONF.identity.region,
81 endpoint_type=CONF.orchestration.endpoint_type,
82 build_interval=CONF.orchestration.build_interval,
83 build_timeout=CONF.orchestration.build_timeout,
84 **self.default_params)
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010085 self.data_processing_client = data_processing.DataProcessingClient(
Ken'ichi Ohmichi4e83b5e2015-02-13 04:07:34 +000086 self.auth_provider,
87 CONF.data_processing.catalog_type,
88 CONF.identity.region,
89 endpoint_type=CONF.data_processing.endpoint_type,
90 **self.default_params_with_timeout_values)
Ken'ichi Ohmichib38eb002015-01-23 02:35:01 +000091 self.negative_client = negative_rest_client.NegativeRestClient(
David Kranz1e33e372015-03-20 09:42:56 -040092 self.auth_provider, service, **self.default_params)
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000093
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010094 def _prepare_configuration(self):
95 """Map values from CONF into Manager parameters
96
97 This uses `config.service_client_config` for all services to collect
98 most configuration items needed to init the clients.
99 """
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +0100100 # NOTE(andreaf) Once all service clients in Tempest are migrated
101 # to tempest.lib, their configuration will be picked up from the
102 # registry, and this method will become redundant.
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100103
104 configuration = {}
105
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +0100106 # Setup the parameters for all Tempest services which are not in lib.
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100107 # NOTE(andreaf) Since client.py is an internal module of Tempest,
108 # it doesn't have to consider plugin configuration.
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +0100109 for service in clients._tempest_internal_modules():
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100110 try:
111 # NOTE(andreaf) Use the unversioned service name to fetch
112 # the configuration since configuration is not versioned.
113 service_for_config = service.split('.')[0]
114 if service_for_config not in configuration:
115 configuration[service_for_config] = (
116 config.service_client_config(service_for_config))
117 except lib_exc.UnknownServiceClient:
118 LOG.warn(
119 'Could not load configuration for service %s' % service)
120
121 return configuration
122
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100123 def _set_network_clients(self):
Andrea Frittoli (andreaf)127c1022016-07-05 23:19:50 +0100124 self.network_agents_client = self.network.AgentsClient()
125 self.network_extensions_client = self.network.ExtensionsClient()
126 self.networks_client = self.network.NetworksClient()
127 self.subnetpools_client = self.network.SubnetpoolsClient()
128 self.subnets_client = self.network.SubnetsClient()
129 self.ports_client = self.network.PortsClient()
130 self.network_quotas_client = self.network.QuotasClient()
131 self.floating_ips_client = self.network.FloatingIPsClient()
132 self.metering_labels_client = self.network.MeteringLabelsClient()
133 self.metering_label_rules_client = (
134 self.network.MeteringLabelRulesClient())
135 self.routers_client = self.network.RoutersClient()
136 self.security_group_rules_client = (
137 self.network.SecurityGroupRulesClient())
138 self.security_groups_client = self.network.SecurityGroupsClient()
139 self.network_versions_client = self.network.NetworkVersionsClient()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100140
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100141 def _set_image_clients(self):
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100142 if CONF.service_available.glance:
Andrea Frittoli (andreaf)e6a9b3f2016-06-30 16:24:32 +0100143 self.image_client = self.image_v1.ImagesClient()
144 self.image_member_client = self.image_v1.ImageMembersClient()
145 self.image_client_v2 = self.image_v2.ImagesClient()
146 self.image_member_client_v2 = self.image_v2.ImageMembersClient()
147 self.namespaces_client = self.image_v2.NamespacesClient()
148 self.resource_types_client = self.image_v2.ResourceTypesClient()
149 self.schemas_client = self.image_v2.SchemasClient()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100150
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000151 def _set_compute_clients(self):
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100152 self.agents_client = self.compute.AgentsClient()
153 self.compute_networks_client = self.compute.NetworksClient()
154 self.migrations_client = self.compute.MigrationsClient()
Ken'ichi Ohmichi65225ef2014-11-19 01:06:25 +0000155 self.security_group_default_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100156 self.compute.SecurityGroupDefaultRulesClient())
157 self.certificates_client = self.compute.CertificatesClient()
158 eip = CONF.compute_feature_enabled.enable_instance_password
159 self.servers_client = self.compute.ServersClient(
160 enable_instance_password=eip)
161 self.server_groups_client = self.compute.ServerGroupsClient()
162 self.limits_client = self.compute.LimitsClient()
163 self.compute_images_client = self.compute.ImagesClient()
164 self.keypairs_client = self.compute.KeyPairsClient()
165 self.quotas_client = self.compute.QuotasClient()
166 self.quota_classes_client = self.compute.QuotaClassesClient()
167 self.flavors_client = self.compute.FlavorsClient()
168 self.extensions_client = self.compute.ExtensionsClient()
169 self.floating_ip_pools_client = self.compute.FloatingIPPoolsClient()
170 self.floating_ips_bulk_client = self.compute.FloatingIPsBulkClient()
171 self.compute_floating_ips_client = self.compute.FloatingIPsClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100172 self.compute_security_group_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100173 self.compute.SecurityGroupRulesClient())
174 self.compute_security_groups_client = (
175 self.compute.SecurityGroupsClient())
176 self.interfaces_client = self.compute.InterfacesClient()
177 self.fixed_ips_client = self.compute.FixedIPsClient()
178 self.availability_zone_client = self.compute.AvailabilityZoneClient()
179 self.aggregates_client = self.compute.AggregatesClient()
180 self.services_client = self.compute.ServicesClient()
181 self.tenant_usages_client = self.compute.TenantUsagesClient()
182 self.hosts_client = self.compute.HostsClient()
183 self.hypervisor_client = self.compute.HypervisorClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100184 self.instance_usages_audit_log_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100185 self.compute.InstanceUsagesAuditLogClient())
186 self.tenant_networks_client = self.compute.TenantNetworksClient()
187 self.baremetal_nodes_client = self.compute.BaremetalNodesClient()
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000188
189 # NOTE: The following client needs special timeout values because
190 # the API is a proxy for the other component.
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100191 params_volume = {}
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100192 for _key in ('build_interval', 'build_timeout'):
193 _value = self.parameters['volume'].get(_key)
194 if _value:
195 params_volume[_key] = _value
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100196 self.volumes_extensions_client = self.compute.VolumesClient(
197 **params_volume)
198 self.compute_versions_client = self.compute.VersionsClient(
199 **params_volume)
200 self.snapshots_extensions_client = self.compute.SnapshotsClient(
201 **params_volume)
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +0000202
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000203 def _set_identity_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100204 params = self.parameters['identity']
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300205
206 # Clients below use the admin endpoint type of Keystone API v2
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100207 params_v2_admin = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300208 params_v2_admin['endpoint_type'] = CONF.identity.v2_admin_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100209 self.endpoints_client = identity.v2.EndpointsClient(self.auth_provider,
210 **params_v2_admin)
211 self.identity_client = identity.v2.IdentityClient(self.auth_provider,
212 **params_v2_admin)
213 self.tenants_client = identity.v2.TenantsClient(self.auth_provider,
214 **params_v2_admin)
215 self.roles_client = identity.v2.RolesClient(self.auth_provider,
216 **params_v2_admin)
217 self.users_client = identity.v2.UsersClient(self.auth_provider,
218 **params_v2_admin)
219 self.identity_services_client = identity.v2.ServicesClient(
Yaroslav Lobankovf6906e12016-02-26 19:44:53 -0600220 self.auth_provider, **params_v2_admin)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300221
222 # Clients below use the public endpoint type of Keystone API v2
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100223 params_v2_public = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300224 params_v2_public['endpoint_type'] = (
225 CONF.identity.v2_public_endpoint_type)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100226 self.identity_public_client = identity.v2.IdentityClient(
227 self.auth_provider, **params_v2_public)
228 self.tenants_public_client = identity.v2.TenantsClient(
229 self.auth_provider, **params_v2_public)
230 self.users_public_client = identity.v2.UsersClient(
231 self.auth_provider, **params_v2_public)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300232
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100233 # Clients below use the endpoint type of Keystone API v3, which is set
234 # in endpoint_type
235 params_v3 = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300236 params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100237 self.domains_client = identity.v3.DomainsClient(self.auth_provider,
238 **params_v3)
239 self.identity_v3_client = identity.v3.IdentityClient(
Yaroslav Lobankov69d90562015-12-18 12:06:40 +0300240 self.auth_provider, **params_v3)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100241 self.trusts_client = identity.v3.TrustsClient(self.auth_provider,
242 **params_v3)
243 self.users_v3_client = identity.v3.UsersClient(self.auth_provider,
244 **params_v3)
245 self.endpoints_v3_client = identity.v3.EndPointsClient(
246 self.auth_provider, **params_v3)
247 self.roles_v3_client = identity.v3.RolesClient(self.auth_provider,
248 **params_v3)
249 self.identity_services_v3_client = identity.v3.ServicesClient(
250 self.auth_provider, **params_v3)
251 self.policies_client = identity.v3.PoliciesClient(self.auth_provider,
252 **params_v3)
253 self.projects_client = identity.v3.ProjectsClient(self.auth_provider,
254 **params_v3)
255 self.regions_client = identity.v3.RegionsClient(self.auth_provider,
256 **params_v3)
257 self.credentials_client = identity.v3.CredentialsClient(
258 self.auth_provider, **params_v3)
259 self.groups_client = identity.v3.GroupsClient(self.auth_provider,
260 **params_v3)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300261
Andrea Frittoli90012352015-02-25 21:58:02 +0000262 # Token clients do not use the catalog. They only need default_params.
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100263 # They read auth_url, so they should only be set if the corresponding
264 # API version is marked as enabled
265 if CONF.identity_feature_enabled.api_v2:
266 if CONF.identity.uri:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100267 self.token_client = identity.v2.TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100268 CONF.identity.uri, **self.default_params)
269 else:
270 msg = 'Identity v2 API enabled, but no identity.uri set'
271 raise exceptions.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000272 if CONF.identity_feature_enabled.api_v3:
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100273 if CONF.identity.uri_v3:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100274 self.token_v3_client = identity.v3.V3TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100275 CONF.identity.uri_v3, **self.default_params)
276 else:
277 msg = 'Identity v3 API enabled, but no identity.uri_v3 set'
278 raise exceptions.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000279
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000280 def _set_volume_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100281 # Mandatory parameters (always defined)
282 params = self.parameters['volume']
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000283
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100284 self.volume_qos_client = volume.v1.QosSpecsClient(self.auth_provider,
285 **params)
286 self.volume_qos_v2_client = volume.v2.QosSpecsClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000287 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100288 self.volume_services_client = volume.v1.ServicesClient(
Yaroslav Lobankov4c237792015-12-02 18:43:48 +0300289 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100290 self.volume_services_v2_client = volume.v2.ServicesClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000291 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100292 self.backups_client = volume.v1.BackupsClient(self.auth_provider,
293 **params)
294 self.backups_v2_client = volume.v2.BackupsClient(self.auth_provider,
295 **params)
296 self.snapshots_client = volume.v1.SnapshotsClient(self.auth_provider,
297 **params)
298 self.snapshots_v2_client = volume.v2.SnapshotsClient(
299 self.auth_provider, **params)
300 self.volumes_client = volume.v1.VolumesClient(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +0000301 self.auth_provider, default_volume_size=CONF.volume.volume_size,
302 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100303 self.volumes_v2_client = volume.v2.VolumesClient(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +0000304 self.auth_provider, default_volume_size=CONF.volume.volume_size,
305 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100306 self.volume_messages_client = volume.v3.MessagesClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000307 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100308 self.volume_types_client = volume.v1.TypesClient(self.auth_provider,
309 **params)
310 self.volume_types_v2_client = volume.v2.TypesClient(self.auth_provider,
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000311 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100312 self.volume_hosts_client = volume.v1.HostsClient(self.auth_provider,
313 **params)
314 self.volume_hosts_v2_client = volume.v2.HostsClient(self.auth_provider,
315 **params)
316 self.volume_quotas_client = volume.v1.QuotasClient(self.auth_provider,
317 **params)
318 self.volume_quotas_v2_client = volume.v2.QuotasClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000319 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100320 self.volumes_extension_client = volume.v1.ExtensionsClient(
321 self.auth_provider, **params)
322 self.volumes_v2_extension_client = volume.v2.ExtensionsClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000323 self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000324 self.volume_availability_zone_client = \
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100325 volume.v1.AvailabilityZoneClient(self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000326 self.volume_v2_availability_zone_client = \
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100327 volume.v2.AvailabilityZoneClient(self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000328
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +0000329 def _set_object_storage_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100330 # Mandatory parameters (always defined)
331 params = self.parameters['object-storage']
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +0000332
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100333 self.account_client = object_storage.AccountClient(self.auth_provider,
334 **params)
335 self.container_client = object_storage.ContainerClient(
336 self.auth_provider, **params)
337 self.object_client = object_storage.ObjectClient(self.auth_provider,
338 **params)
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100339
340
341def get_auth_provider_class(credentials):
342 if isinstance(credentials, auth.KeystoneV3Credentials):
343 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
344 else:
345 return auth.KeystoneV2AuthProvider, CONF.identity.uri
346
347
348def get_auth_provider(credentials, pre_auth=False, scope='project'):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100349 # kwargs for auth provider match the common ones used by service clients
350 default_params = config.service_client_config()
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100351 if credentials is None:
352 raise exceptions.InvalidCredentials(
353 'Credentials must be specified')
354 auth_provider_class, auth_url = get_auth_provider_class(
355 credentials)
356 _auth_provider = auth_provider_class(credentials, auth_url,
357 scope=scope,
358 **default_params)
359 if pre_auth:
360 _auth_provider.set_auth()
361 return _auth_provider