blob: 42bd8f54fde9a1bbc8009270b9142a0151d7760e [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
ChangBo Guo(gcb)9f147892016-09-21 14:01:32 +080017
Doug Hellmann583ce2c2015-03-11 14:55:46 +000018from oslo_log import log as logging
ChangBo Guo(gcb)9f147892016-09-21 14:01:32 +080019
Jay Pipesf38eaac2012-06-21 13:37:35 -040020from tempest import config
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
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +010025from tempest.services import identity
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +010026from tempest.services import object_storage
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010027from tempest.services import orchestration
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +010028from tempest.services import volume
Vincent Hou6b8a7b72012-08-25 01:24:33 +080029
Sean Dague86bd8422013-12-20 09:56:44 -050030CONF = config.CONF
Jay Pipes3f981df2012-03-27 18:59:44 -040031LOG = logging.getLogger(__name__)
32
Vincent Hou6b8a7b72012-08-25 01:24:33 +080033
Andrea Frittoli (andreaf)e07579c2016-08-05 07:27:02 +010034class Manager(clients.ServiceClients):
Ken'ichi Ohmichi2e2ee192015-11-19 09:48:27 +000035 """Top level manager for OpenStack tempest clients"""
Jay Pipes3f981df2012-03-27 18:59:44 -040036
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010037 default_params = config.service_client_config()
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000038
Jordan Pittier7efc1552016-09-30 12:03:35 +020039 # TODO(andreaf) This is only used by baremetal clients,
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010040 # and should be removed once they are out of Tempest
Ken'ichi Ohmichi737a6032015-01-21 07:04:42 +000041 default_params_with_timeout_values = {
42 'build_interval': CONF.compute.build_interval,
43 'build_timeout': CONF.compute.build_timeout
44 }
45 default_params_with_timeout_values.update(default_params)
46
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010047 def __init__(self, credentials, service=None, scope='project'):
ghanshyam4e2be342015-11-27 18:07:46 +090048 """Initialization of Manager class.
Brant Knudsonc7ca3342013-03-28 21:08:50 -050049
ghanshyam4e2be342015-11-27 18:07:46 +090050 Setup all services clients and make them available for tests cases.
51 :param credentials: type Credentials or TestResources
52 :param service: Service name
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010053 :param scope: default scope for tokens produced by the auth provider
ghanshyam4e2be342015-11-27 18:07:46 +090054 """
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010055 _, identity_uri = get_auth_provider_class(credentials)
56 super(Manager, self).__init__(
57 credentials=credentials, identity_uri=identity_uri, scope=scope,
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010058 region=CONF.identity.region,
59 client_parameters=self._prepare_configuration())
60 # TODO(andreaf) When clients are initialised without the right
61 # parameters available, the calls below will trigger a KeyError.
62 # We should catch that and raise a better error.
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +000063 self._set_compute_clients()
64 self._set_identity_clients()
65 self._set_volume_clients()
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +000066 self._set_object_storage_clients()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010067 self._set_image_clients()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010068 self._set_network_clients()
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +000069
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010070 self.baremetal_client = baremetal.BaremetalClient(
Ken'ichi Ohmichi1f88ece2015-01-23 03:33:11 +000071 self.auth_provider,
72 CONF.baremetal.catalog_type,
73 CONF.identity.region,
74 endpoint_type=CONF.baremetal.endpoint_type,
75 **self.default_params_with_timeout_values)
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010076 self.orchestration_client = orchestration.OrchestrationClient(
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000077 self.auth_provider,
78 CONF.orchestration.catalog_type,
79 CONF.orchestration.region or CONF.identity.region,
80 endpoint_type=CONF.orchestration.endpoint_type,
81 build_interval=CONF.orchestration.build_interval,
82 build_timeout=CONF.orchestration.build_timeout,
83 **self.default_params)
84
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010085 def _prepare_configuration(self):
86 """Map values from CONF into Manager parameters
87
88 This uses `config.service_client_config` for all services to collect
89 most configuration items needed to init the clients.
90 """
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +010091 # NOTE(andreaf) Once all service clients in Tempest are migrated
92 # to tempest.lib, their configuration will be picked up from the
93 # registry, and this method will become redundant.
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010094
95 configuration = {}
96
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +010097 # Setup the parameters for all Tempest services which are not in lib.
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010098 # NOTE(andreaf) Since client.py is an internal module of Tempest,
99 # it doesn't have to consider plugin configuration.
Andrea Frittoli (andreaf)8420abe2016-07-27 11:47:43 +0100100 for service in clients._tempest_internal_modules():
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100101 try:
102 # NOTE(andreaf) Use the unversioned service name to fetch
103 # the configuration since configuration is not versioned.
104 service_for_config = service.split('.')[0]
105 if service_for_config not in configuration:
106 configuration[service_for_config] = (
107 config.service_client_config(service_for_config))
108 except lib_exc.UnknownServiceClient:
Cao Xuan Hoang738ffcb2016-09-26 15:35:23 +0700109 LOG.warning(
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100110 'Could not load configuration for service %s' % service)
111
112 return configuration
113
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100114 def _set_network_clients(self):
Andrea Frittoli (andreaf)127c1022016-07-05 23:19:50 +0100115 self.network_agents_client = self.network.AgentsClient()
116 self.network_extensions_client = self.network.ExtensionsClient()
117 self.networks_client = self.network.NetworksClient()
118 self.subnetpools_client = self.network.SubnetpoolsClient()
119 self.subnets_client = self.network.SubnetsClient()
120 self.ports_client = self.network.PortsClient()
121 self.network_quotas_client = self.network.QuotasClient()
122 self.floating_ips_client = self.network.FloatingIPsClient()
123 self.metering_labels_client = self.network.MeteringLabelsClient()
124 self.metering_label_rules_client = (
125 self.network.MeteringLabelRulesClient())
126 self.routers_client = self.network.RoutersClient()
127 self.security_group_rules_client = (
128 self.network.SecurityGroupRulesClient())
129 self.security_groups_client = self.network.SecurityGroupsClient()
130 self.network_versions_client = self.network.NetworkVersionsClient()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100131
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100132 def _set_image_clients(self):
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100133 if CONF.service_available.glance:
Andrea Frittoli (andreaf)e6a9b3f2016-06-30 16:24:32 +0100134 self.image_client = self.image_v1.ImagesClient()
135 self.image_member_client = self.image_v1.ImageMembersClient()
136 self.image_client_v2 = self.image_v2.ImagesClient()
137 self.image_member_client_v2 = self.image_v2.ImageMembersClient()
138 self.namespaces_client = self.image_v2.NamespacesClient()
139 self.resource_types_client = self.image_v2.ResourceTypesClient()
140 self.schemas_client = self.image_v2.SchemasClient()
guo yunxian753e90a2016-11-17 20:12:22 +0800141 self.namespace_properties_client = \
142 self.image_v2.NamespacePropertiesClient()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100143
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000144 def _set_compute_clients(self):
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100145 self.agents_client = self.compute.AgentsClient()
146 self.compute_networks_client = self.compute.NetworksClient()
147 self.migrations_client = self.compute.MigrationsClient()
Ken'ichi Ohmichi65225ef2014-11-19 01:06:25 +0000148 self.security_group_default_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100149 self.compute.SecurityGroupDefaultRulesClient())
150 self.certificates_client = self.compute.CertificatesClient()
151 eip = CONF.compute_feature_enabled.enable_instance_password
152 self.servers_client = self.compute.ServersClient(
153 enable_instance_password=eip)
154 self.server_groups_client = self.compute.ServerGroupsClient()
155 self.limits_client = self.compute.LimitsClient()
156 self.compute_images_client = self.compute.ImagesClient()
157 self.keypairs_client = self.compute.KeyPairsClient()
158 self.quotas_client = self.compute.QuotasClient()
159 self.quota_classes_client = self.compute.QuotaClassesClient()
160 self.flavors_client = self.compute.FlavorsClient()
161 self.extensions_client = self.compute.ExtensionsClient()
162 self.floating_ip_pools_client = self.compute.FloatingIPPoolsClient()
163 self.floating_ips_bulk_client = self.compute.FloatingIPsBulkClient()
164 self.compute_floating_ips_client = self.compute.FloatingIPsClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100165 self.compute_security_group_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100166 self.compute.SecurityGroupRulesClient())
167 self.compute_security_groups_client = (
168 self.compute.SecurityGroupsClient())
169 self.interfaces_client = self.compute.InterfacesClient()
170 self.fixed_ips_client = self.compute.FixedIPsClient()
171 self.availability_zone_client = self.compute.AvailabilityZoneClient()
172 self.aggregates_client = self.compute.AggregatesClient()
173 self.services_client = self.compute.ServicesClient()
174 self.tenant_usages_client = self.compute.TenantUsagesClient()
175 self.hosts_client = self.compute.HostsClient()
176 self.hypervisor_client = self.compute.HypervisorClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100177 self.instance_usages_audit_log_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100178 self.compute.InstanceUsagesAuditLogClient())
179 self.tenant_networks_client = self.compute.TenantNetworksClient()
180 self.baremetal_nodes_client = self.compute.BaremetalNodesClient()
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000181
182 # NOTE: The following client needs special timeout values because
183 # the API is a proxy for the other component.
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100184 params_volume = {}
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100185 for _key in ('build_interval', 'build_timeout'):
186 _value = self.parameters['volume'].get(_key)
187 if _value:
188 params_volume[_key] = _value
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100189 self.volumes_extensions_client = self.compute.VolumesClient(
190 **params_volume)
191 self.compute_versions_client = self.compute.VersionsClient(
192 **params_volume)
193 self.snapshots_extensions_client = self.compute.SnapshotsClient(
194 **params_volume)
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +0000195
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000196 def _set_identity_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100197 params = self.parameters['identity']
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300198
199 # Clients below use the admin endpoint type of Keystone API v2
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100200 params_v2_admin = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300201 params_v2_admin['endpoint_type'] = CONF.identity.v2_admin_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100202 self.endpoints_client = identity.v2.EndpointsClient(self.auth_provider,
203 **params_v2_admin)
204 self.identity_client = identity.v2.IdentityClient(self.auth_provider,
205 **params_v2_admin)
206 self.tenants_client = identity.v2.TenantsClient(self.auth_provider,
207 **params_v2_admin)
208 self.roles_client = identity.v2.RolesClient(self.auth_provider,
209 **params_v2_admin)
210 self.users_client = identity.v2.UsersClient(self.auth_provider,
211 **params_v2_admin)
212 self.identity_services_client = identity.v2.ServicesClient(
Yaroslav Lobankovf6906e12016-02-26 19:44:53 -0600213 self.auth_provider, **params_v2_admin)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300214
215 # Clients below use the public endpoint type of Keystone API v2
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100216 params_v2_public = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300217 params_v2_public['endpoint_type'] = (
218 CONF.identity.v2_public_endpoint_type)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100219 self.identity_public_client = identity.v2.IdentityClient(
220 self.auth_provider, **params_v2_public)
221 self.tenants_public_client = identity.v2.TenantsClient(
222 self.auth_provider, **params_v2_public)
223 self.users_public_client = identity.v2.UsersClient(
224 self.auth_provider, **params_v2_public)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300225
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100226 # Clients below use the endpoint type of Keystone API v3, which is set
227 # in endpoint_type
228 params_v3 = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300229 params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100230 self.domains_client = identity.v3.DomainsClient(self.auth_provider,
231 **params_v3)
232 self.identity_v3_client = identity.v3.IdentityClient(
Yaroslav Lobankov69d90562015-12-18 12:06:40 +0300233 self.auth_provider, **params_v3)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100234 self.trusts_client = identity.v3.TrustsClient(self.auth_provider,
235 **params_v3)
236 self.users_v3_client = identity.v3.UsersClient(self.auth_provider,
237 **params_v3)
238 self.endpoints_v3_client = identity.v3.EndPointsClient(
239 self.auth_provider, **params_v3)
240 self.roles_v3_client = identity.v3.RolesClient(self.auth_provider,
241 **params_v3)
ghanshyamad55eb82016-09-06 13:58:29 +0900242 self.inherited_roles_client = identity.v3.InheritedRolesClient(
243 self.auth_provider, **params_v3)
Rodrigo Duarte12f8d4a2016-07-08 11:53:53 -0300244 self.role_assignments_client = identity.v3.RoleAssignmentsClient(
245 self.auth_provider, **params_v3)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100246 self.identity_services_v3_client = identity.v3.ServicesClient(
247 self.auth_provider, **params_v3)
248 self.policies_client = identity.v3.PoliciesClient(self.auth_provider,
249 **params_v3)
250 self.projects_client = identity.v3.ProjectsClient(self.auth_provider,
251 **params_v3)
252 self.regions_client = identity.v3.RegionsClient(self.auth_provider,
253 **params_v3)
254 self.credentials_client = identity.v3.CredentialsClient(
255 self.auth_provider, **params_v3)
256 self.groups_client = identity.v3.GroupsClient(self.auth_provider,
257 **params_v3)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300258
Andrea Frittoli90012352015-02-25 21:58:02 +0000259 # Token clients do not use the catalog. They only need default_params.
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100260 # They read auth_url, so they should only be set if the corresponding
261 # API version is marked as enabled
262 if CONF.identity_feature_enabled.api_v2:
263 if CONF.identity.uri:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100264 self.token_client = identity.v2.TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100265 CONF.identity.uri, **self.default_params)
266 else:
267 msg = 'Identity v2 API enabled, but no identity.uri set'
Matthew Treinish4217a702016-10-07 17:27:11 -0400268 raise lib_exc.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000269 if CONF.identity_feature_enabled.api_v3:
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100270 if CONF.identity.uri_v3:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100271 self.token_v3_client = identity.v3.V3TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100272 CONF.identity.uri_v3, **self.default_params)
273 else:
274 msg = 'Identity v3 API enabled, but no identity.uri_v3 set'
Matthew Treinish4217a702016-10-07 17:27:11 -0400275 raise lib_exc.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000276
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000277 def _set_volume_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100278 # Mandatory parameters (always defined)
279 params = self.parameters['volume']
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000280
lkuchlan3fce7fb2016-10-31 15:40:35 +0200281 self.volume_qos_client = self.volume_v1.QosSpecsClient()
282 self.volume_qos_v2_client = self.volume_v2.QosSpecsClient()
283 self.volume_services_client = self.volume_v1.ServicesClient()
284 self.volume_services_v2_client = self.volume_v2.ServicesClient()
285 self.backups_client = self.volume_v1.BackupsClient()
286 self.backups_v2_client = self.volume_v2.BackupsClient()
287 self.encryption_types_client = self.volume_v1.EncryptionTypesClient()
288 self.encryption_types_v2_client = \
289 self.volume_v2.EncryptionTypesClient()
290 self.snapshots_client = self.volume_v1.SnapshotsClient()
291 self.snapshots_v2_client = self.volume_v2.SnapshotsClient()
292 self.volumes_client = self.volume_v1.VolumesClient()
293 self.volumes_v2_client = self.volume_v2.VolumesClient()
Benny Kopilove43b6e02016-11-03 10:51:34 +0200294 self.volume_v3_messages_client = volume.v3.MessagesClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000295 self.auth_provider, **params)
lkuchlan3fce7fb2016-10-31 15:40:35 +0200296 self.volume_types_client = self.volume_v1.TypesClient()
297 self.volume_types_v2_client = self.volume_v2.TypesClient()
298 self.volume_hosts_client = self.volume_v1.HostsClient()
299 self.volume_hosts_v2_client = self.volume_v2.HostsClient()
300 self.volume_quotas_client = self.volume_v1.QuotasClient()
301 self.volume_quotas_v2_client = self.volume_v2.QuotasClient()
302 self.volumes_extension_client = self.volume_v1.ExtensionsClient()
303 self.volumes_v2_extension_client = self.volume_v2.ExtensionsClient()
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000304 self.volume_availability_zone_client = \
lkuchlan3fce7fb2016-10-31 15:40:35 +0200305 self.volume_v1.AvailabilityZoneClient()
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000306 self.volume_v2_availability_zone_client = \
lkuchlan3fce7fb2016-10-31 15:40:35 +0200307 self.volume_v2.AvailabilityZoneClient()
bkopilov14193082016-05-31 10:01:28 +0300308 self.volume_limits_client = self.volume_v1.LimitsClient()
309 self.volume_v2_limits_client = self.volume_v2.LimitsClient()
lkuchlan7bba16c2016-09-04 12:36:04 +0300310 self.volume_capabilities_v2_client = \
311 self.volume_v2.CapabilitiesClient()
312 self.volume_scheduler_stats_v2_client = \
313 self.volume_v2.SchedulerStatsClient()
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000314
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +0000315 def _set_object_storage_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100316 # Mandatory parameters (always defined)
317 params = self.parameters['object-storage']
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +0000318
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100319 self.account_client = object_storage.AccountClient(self.auth_provider,
320 **params)
321 self.container_client = object_storage.ContainerClient(
322 self.auth_provider, **params)
323 self.object_client = object_storage.ObjectClient(self.auth_provider,
324 **params)
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100325
326
327def get_auth_provider_class(credentials):
328 if isinstance(credentials, auth.KeystoneV3Credentials):
329 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
330 else:
331 return auth.KeystoneV2AuthProvider, CONF.identity.uri
332
333
334def get_auth_provider(credentials, pre_auth=False, scope='project'):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100335 # kwargs for auth provider match the common ones used by service clients
336 default_params = config.service_client_config()
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100337 if credentials is None:
guo yunxian654a9212016-11-02 17:26:42 +0800338 raise lib_exc.InvalidCredentials(
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100339 'Credentials must be specified')
340 auth_provider_class, auth_url = get_auth_provider_class(
341 credentials)
342 _auth_provider = auth_provider_class(credentials, auth_url,
343 scope=scope,
344 **default_params)
345 if pre_auth:
346 _auth_provider.set_auth()
347 return _auth_provider