blob: ef03e80dadf712be54f7d98f4dc35dc91fd9263f [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
17
Doug Hellmann583ce2c2015-03-11 14:55:46 +000018from oslo_log import log as logging
19
Ken'ichi Ohmichi42662682015-01-05 05:00:04 +000020from tempest.common import negative_rest_client
Jay Pipesf38eaac2012-06-21 13:37:35 -040021from tempest import config
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +010022from tempest import exceptions
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010023from tempest.lib import auth
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +010024from tempest.lib.services import compute
Ken'ichi Ohmichi41721012016-06-22 10:41:26 -070025from tempest.lib.services import image
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +010026from tempest.lib.services import network
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010027from tempest import service_clients
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010028from tempest.services import baremetal
29from tempest.services import data_processing
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +010030from tempest.services import identity
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +010031from tempest.services import object_storage
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010032from tempest.services import orchestration
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +010033from tempest.services import volume
Vincent Hou6b8a7b72012-08-25 01:24:33 +080034
Sean Dague86bd8422013-12-20 09:56:44 -050035CONF = config.CONF
Jay Pipes3f981df2012-03-27 18:59:44 -040036LOG = logging.getLogger(__name__)
37
Vincent Hou6b8a7b72012-08-25 01:24:33 +080038
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010039class Manager(service_clients.ServiceClients):
Ken'ichi Ohmichi2e2ee192015-11-19 09:48:27 +000040 """Top level manager for OpenStack tempest clients"""
Jay Pipes3f981df2012-03-27 18:59:44 -040041
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000042 default_params = {
43 'disable_ssl_certificate_validation':
44 CONF.identity.disable_ssl_certificate_validation,
45 'ca_certs': CONF.identity.ca_certificates_file,
46 'trace_requests': CONF.debug.trace_requests
47 }
48
Ken'ichi Ohmichi737a6032015-01-21 07:04:42 +000049 # NOTE: Tempest uses timeout values of compute API if project specific
50 # timeout values don't exist.
51 default_params_with_timeout_values = {
52 'build_interval': CONF.compute.build_interval,
53 'build_timeout': CONF.compute.build_timeout
54 }
55 default_params_with_timeout_values.update(default_params)
56
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010057 def __init__(self, credentials, service=None, scope='project'):
ghanshyam4e2be342015-11-27 18:07:46 +090058 """Initialization of Manager class.
Brant Knudsonc7ca3342013-03-28 21:08:50 -050059
ghanshyam4e2be342015-11-27 18:07:46 +090060 Setup all services clients and make them available for tests cases.
61 :param credentials: type Credentials or TestResources
62 :param service: Service name
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010063 :param scope: default scope for tokens produced by the auth provider
ghanshyam4e2be342015-11-27 18:07:46 +090064 """
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010065 _, identity_uri = get_auth_provider_class(credentials)
66 super(Manager, self).__init__(
67 credentials=credentials, identity_uri=identity_uri, scope=scope,
68 region=CONF.identity.region, **self.default_params)
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +000069 self._set_compute_clients()
70 self._set_identity_clients()
71 self._set_volume_clients()
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +000072 self._set_object_storage_clients()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010073 self._set_image_clients()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010074 self._set_network_clients()
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +000075
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010076 self.baremetal_client = baremetal.BaremetalClient(
Ken'ichi Ohmichi1f88ece2015-01-23 03:33:11 +000077 self.auth_provider,
78 CONF.baremetal.catalog_type,
79 CONF.identity.region,
80 endpoint_type=CONF.baremetal.endpoint_type,
81 **self.default_params_with_timeout_values)
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010082 self.orchestration_client = orchestration.OrchestrationClient(
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000083 self.auth_provider,
84 CONF.orchestration.catalog_type,
85 CONF.orchestration.region or CONF.identity.region,
86 endpoint_type=CONF.orchestration.endpoint_type,
87 build_interval=CONF.orchestration.build_interval,
88 build_timeout=CONF.orchestration.build_timeout,
89 **self.default_params)
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010090 self.data_processing_client = data_processing.DataProcessingClient(
Ken'ichi Ohmichi4e83b5e2015-02-13 04:07:34 +000091 self.auth_provider,
92 CONF.data_processing.catalog_type,
93 CONF.identity.region,
94 endpoint_type=CONF.data_processing.endpoint_type,
95 **self.default_params_with_timeout_values)
Ken'ichi Ohmichib38eb002015-01-23 02:35:01 +000096 self.negative_client = negative_rest_client.NegativeRestClient(
David Kranz1e33e372015-03-20 09:42:56 -040097 self.auth_provider, service, **self.default_params)
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000098
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010099 def _set_network_clients(self):
100 params = {
101 'service': CONF.network.catalog_type,
102 'region': CONF.network.region or CONF.identity.region,
103 'endpoint_type': CONF.network.endpoint_type,
104 'build_interval': CONF.network.build_interval,
105 'build_timeout': CONF.network.build_timeout
106 }
107 params.update(self.default_params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100108 self.network_agents_client = network.AgentsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100109 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100110 self.network_extensions_client = network.ExtensionsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100111 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100112 self.networks_client = network.NetworksClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100113 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100114 self.subnetpools_client = network.SubnetpoolsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100115 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100116 self.subnets_client = network.SubnetsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100117 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100118 self.ports_client = network.PortsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100119 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100120 self.network_quotas_client = network.QuotasClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100121 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100122 self.floating_ips_client = network.FloatingIPsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100123 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100124 self.metering_labels_client = network.MeteringLabelsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100125 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100126 self.metering_label_rules_client = network.MeteringLabelRulesClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100127 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100128 self.routers_client = network.RoutersClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100129 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100130 self.security_group_rules_client = network.SecurityGroupRulesClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100131 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100132 self.security_groups_client = network.SecurityGroupsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100133 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100134 self.network_versions_client = network.NetworkVersionsClient(
Mark T. Voelkerabd4cbd2016-04-29 12:03:04 -0500135 self.auth_provider, **params)
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100136
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100137 def _set_image_clients(self):
138 params = {
139 'service': CONF.image.catalog_type,
140 'region': CONF.image.region or CONF.identity.region,
141 'endpoint_type': CONF.image.endpoint_type,
142 'build_interval': CONF.image.build_interval,
143 'build_timeout': CONF.image.build_timeout
144 }
145 params.update(self.default_params)
146
147 if CONF.service_available.glance:
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100148 self.image_client = image.v1.ImagesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100149 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100150 self.image_member_client = image.v1.ImageMembersClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100151 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100152 self.image_client_v2 = image.v2.ImagesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100153 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100154 self.image_member_client_v2 = image.v2.ImageMembersClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100155 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100156 self.namespaces_client = image.v2.NamespacesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100157 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100158 self.resource_types_client = image.v2.ResourceTypesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100159 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100160 self.schemas_client = image.v2.SchemasClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100161 self.auth_provider, **params)
162
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000163 def _set_compute_clients(self):
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000164 params = {
165 'service': CONF.compute.catalog_type,
166 'region': CONF.compute.region or CONF.identity.region,
167 'endpoint_type': CONF.compute.endpoint_type,
168 'build_interval': CONF.compute.build_interval,
169 'build_timeout': CONF.compute.build_timeout
170 }
171 params.update(self.default_params)
172
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100173 self.agents_client = compute.AgentsClient(self.auth_provider, **params)
174 self.compute_networks_client = compute.NetworksClient(
John Warren9487a182015-09-14 18:12:56 -0400175 self.auth_provider, **params)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100176 self.migrations_client = compute.MigrationsClient(self.auth_provider,
177 **params)
Ken'ichi Ohmichi65225ef2014-11-19 01:06:25 +0000178 self.security_group_default_rules_client = (
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100179 compute.SecurityGroupDefaultRulesClient(self.auth_provider,
180 **params))
181 self.certificates_client = compute.CertificatesClient(
182 self.auth_provider, **params)
183 self.servers_client = compute.ServersClient(
Masayuki Igawa8f9c0c82015-03-03 09:38:08 +0900184 self.auth_provider,
185 enable_instance_password=CONF.compute_feature_enabled
186 .enable_instance_password,
187 **params)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100188 self.server_groups_client = compute.ServerGroupsClient(
Ken'ichi Ohmichi7ca54b82015-07-07 01:10:26 +0000189 self.auth_provider, **params)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100190 self.limits_client = compute.LimitsClient(self.auth_provider, **params)
191 self.compute_images_client = compute.ImagesClient(self.auth_provider,
192 **params)
193 self.keypairs_client = compute.KeyPairsClient(self.auth_provider,
194 **params)
195 self.quotas_client = compute.QuotasClient(self.auth_provider, **params)
196 self.quota_classes_client = compute.QuotaClassesClient(
197 self.auth_provider, **params)
198 self.flavors_client = compute.FlavorsClient(self.auth_provider,
199 **params)
200 self.extensions_client = compute.ExtensionsClient(self.auth_provider,
201 **params)
202 self.floating_ip_pools_client = compute.FloatingIPPoolsClient(
203 self.auth_provider, **params)
204 self.floating_ips_bulk_client = compute.FloatingIPsBulkClient(
205 self.auth_provider, **params)
206 self.compute_floating_ips_client = compute.FloatingIPsClient(
207 self.auth_provider, **params)
208 self.compute_security_group_rules_client = (
209 compute.SecurityGroupRulesClient(self.auth_provider, **params))
210 self.compute_security_groups_client = compute.SecurityGroupsClient(
211 self.auth_provider, **params)
212 self.interfaces_client = compute.InterfacesClient(self.auth_provider,
213 **params)
214 self.fixed_ips_client = compute.FixedIPsClient(self.auth_provider,
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +0000215 **params)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100216 self.availability_zone_client = compute.AvailabilityZoneClient(
Ken'ichi Ohmichi03af1c52015-07-13 00:28:05 +0000217 self.auth_provider, **params)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100218 self.aggregates_client = compute.AggregatesClient(self.auth_provider,
219 **params)
220 self.services_client = compute.ServicesClient(self.auth_provider,
221 **params)
222 self.tenant_usages_client = compute.TenantUsagesClient(
Ken'ichi Ohmichi2b26e752015-07-13 00:44:36 +0000223 self.auth_provider, **params)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100224 self.hosts_client = compute.HostsClient(self.auth_provider, **params)
225 self.hypervisor_client = compute.HypervisorClient(self.auth_provider,
226 **params)
227 self.instance_usages_audit_log_client = (
228 compute.InstanceUsagesAuditLogClient(self.auth_provider, **params))
229 self.tenant_networks_client = compute.TenantNetworksClient(
John Warrene74890a2015-11-11 15:18:01 -0500230 self.auth_provider, **params)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100231 self.baremetal_nodes_client = compute.BaremetalNodesClient(
YuikoTakadaac0879a2015-01-22 02:40:03 +0000232 self.auth_provider, **params)
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000233
234 # NOTE: The following client needs special timeout values because
235 # the API is a proxy for the other component.
236 params_volume = copy.deepcopy(params)
237 params_volume.update({
238 'build_interval': CONF.volume.build_interval,
239 'build_timeout': CONF.volume.build_timeout
240 })
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100241 self.volumes_extensions_client = compute.VolumesClient(
Ken'ichi Ohmichic4921782015-08-05 08:14:42 +0000242 self.auth_provider, **params_volume)
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100243 self.compute_versions_client = compute.VersionsClient(
244 self.auth_provider, **params_volume)
245 self.snapshots_extensions_client = compute.SnapshotsClient(
Gaozexub9c9d6e2015-09-10 17:08:04 +0800246 self.auth_provider, **params_volume)
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +0000247
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000248 def _set_identity_clients(self):
ghanshyamd26b5cd2015-02-09 14:48:58 +0900249 params = {
250 'service': CONF.identity.catalog_type,
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300251 'region': CONF.identity.region
ghanshyamd26b5cd2015-02-09 14:48:58 +0900252 }
253 params.update(self.default_params_with_timeout_values)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300254
255 # Clients below use the admin endpoint type of Keystone API v2
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300256 params_v2_admin = params.copy()
257 params_v2_admin['endpoint_type'] = CONF.identity.v2_admin_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100258 self.endpoints_client = identity.v2.EndpointsClient(self.auth_provider,
259 **params_v2_admin)
260 self.identity_client = identity.v2.IdentityClient(self.auth_provider,
261 **params_v2_admin)
262 self.tenants_client = identity.v2.TenantsClient(self.auth_provider,
263 **params_v2_admin)
264 self.roles_client = identity.v2.RolesClient(self.auth_provider,
265 **params_v2_admin)
266 self.users_client = identity.v2.UsersClient(self.auth_provider,
267 **params_v2_admin)
268 self.identity_services_client = identity.v2.ServicesClient(
Yaroslav Lobankovf6906e12016-02-26 19:44:53 -0600269 self.auth_provider, **params_v2_admin)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300270
271 # Clients below use the public endpoint type of Keystone API v2
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300272 params_v2_public = params.copy()
273 params_v2_public['endpoint_type'] = (
274 CONF.identity.v2_public_endpoint_type)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100275 self.identity_public_client = identity.v2.IdentityClient(
276 self.auth_provider, **params_v2_public)
277 self.tenants_public_client = identity.v2.TenantsClient(
278 self.auth_provider, **params_v2_public)
279 self.users_public_client = identity.v2.UsersClient(
280 self.auth_provider, **params_v2_public)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300281
282 # Clients below use the endpoint type of Keystone API v3
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300283 params_v3 = params.copy()
284 params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100285 self.domains_client = identity.v3.DomainsClient(self.auth_provider,
286 **params_v3)
287 self.identity_v3_client = identity.v3.IdentityClient(
Yaroslav Lobankov69d90562015-12-18 12:06:40 +0300288 self.auth_provider, **params_v3)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100289 self.trusts_client = identity.v3.TrustsClient(self.auth_provider,
290 **params_v3)
291 self.users_v3_client = identity.v3.UsersClient(self.auth_provider,
292 **params_v3)
293 self.endpoints_v3_client = identity.v3.EndPointsClient(
294 self.auth_provider, **params_v3)
295 self.roles_v3_client = identity.v3.RolesClient(self.auth_provider,
296 **params_v3)
297 self.identity_services_v3_client = identity.v3.ServicesClient(
298 self.auth_provider, **params_v3)
299 self.policies_client = identity.v3.PoliciesClient(self.auth_provider,
300 **params_v3)
301 self.projects_client = identity.v3.ProjectsClient(self.auth_provider,
302 **params_v3)
303 self.regions_client = identity.v3.RegionsClient(self.auth_provider,
304 **params_v3)
305 self.credentials_client = identity.v3.CredentialsClient(
306 self.auth_provider, **params_v3)
307 self.groups_client = identity.v3.GroupsClient(self.auth_provider,
308 **params_v3)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300309
Andrea Frittoli90012352015-02-25 21:58:02 +0000310 # Token clients do not use the catalog. They only need default_params.
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100311 # They read auth_url, so they should only be set if the corresponding
312 # API version is marked as enabled
313 if CONF.identity_feature_enabled.api_v2:
314 if CONF.identity.uri:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100315 self.token_client = identity.v2.TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100316 CONF.identity.uri, **self.default_params)
317 else:
318 msg = 'Identity v2 API enabled, but no identity.uri set'
319 raise exceptions.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000320 if CONF.identity_feature_enabled.api_v3:
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100321 if CONF.identity.uri_v3:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100322 self.token_v3_client = identity.v3.V3TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100323 CONF.identity.uri_v3, **self.default_params)
324 else:
325 msg = 'Identity v3 API enabled, but no identity.uri_v3 set'
326 raise exceptions.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000327
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000328 def _set_volume_clients(self):
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000329 params = {
330 'service': CONF.volume.catalog_type,
331 'region': CONF.volume.region or CONF.identity.region,
332 'endpoint_type': CONF.volume.endpoint_type,
333 'build_interval': CONF.volume.build_interval,
334 'build_timeout': CONF.volume.build_timeout
335 }
336 params.update(self.default_params)
337
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100338 self.volume_qos_client = volume.v1.QosSpecsClient(self.auth_provider,
339 **params)
340 self.volume_qos_v2_client = volume.v2.QosSpecsClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000341 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100342 self.volume_services_client = volume.v1.ServicesClient(
Yaroslav Lobankov4c237792015-12-02 18:43:48 +0300343 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100344 self.volume_services_v2_client = volume.v2.ServicesClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000345 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100346 self.backups_client = volume.v1.BackupsClient(self.auth_provider,
347 **params)
348 self.backups_v2_client = volume.v2.BackupsClient(self.auth_provider,
349 **params)
350 self.snapshots_client = volume.v1.SnapshotsClient(self.auth_provider,
351 **params)
352 self.snapshots_v2_client = volume.v2.SnapshotsClient(
353 self.auth_provider, **params)
354 self.volumes_client = volume.v1.VolumesClient(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +0000355 self.auth_provider, default_volume_size=CONF.volume.volume_size,
356 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100357 self.volumes_v2_client = volume.v2.VolumesClient(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +0000358 self.auth_provider, default_volume_size=CONF.volume.volume_size,
359 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100360 self.volume_messages_client = volume.v3.MessagesClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000361 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100362 self.volume_types_client = volume.v1.TypesClient(self.auth_provider,
363 **params)
364 self.volume_types_v2_client = volume.v2.TypesClient(self.auth_provider,
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000365 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100366 self.volume_hosts_client = volume.v1.HostsClient(self.auth_provider,
367 **params)
368 self.volume_hosts_v2_client = volume.v2.HostsClient(self.auth_provider,
369 **params)
370 self.volume_quotas_client = volume.v1.QuotasClient(self.auth_provider,
371 **params)
372 self.volume_quotas_v2_client = volume.v2.QuotasClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000373 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100374 self.volumes_extension_client = volume.v1.ExtensionsClient(
375 self.auth_provider, **params)
376 self.volumes_v2_extension_client = volume.v2.ExtensionsClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000377 self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000378 self.volume_availability_zone_client = \
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100379 volume.v1.AvailabilityZoneClient(self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000380 self.volume_v2_availability_zone_client = \
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100381 volume.v2.AvailabilityZoneClient(self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000382
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +0000383 def _set_object_storage_clients(self):
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +0000384 params = {
385 'service': CONF.object_storage.catalog_type,
386 'region': CONF.object_storage.region or CONF.identity.region,
387 'endpoint_type': CONF.object_storage.endpoint_type
388 }
389 params.update(self.default_params_with_timeout_values)
390
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100391 self.account_client = object_storage.AccountClient(self.auth_provider,
392 **params)
393 self.container_client = object_storage.ContainerClient(
394 self.auth_provider, **params)
395 self.object_client = object_storage.ObjectClient(self.auth_provider,
396 **params)
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100397
398
399def get_auth_provider_class(credentials):
400 if isinstance(credentials, auth.KeystoneV3Credentials):
401 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
402 else:
403 return auth.KeystoneV2AuthProvider, CONF.identity.uri
404
405
406def get_auth_provider(credentials, pre_auth=False, scope='project'):
407 default_params = {
408 'disable_ssl_certificate_validation':
409 CONF.identity.disable_ssl_certificate_validation,
410 'ca_certs': CONF.identity.ca_certificates_file,
411 'trace_requests': CONF.debug.trace_requests
412 }
413 if credentials is None:
414 raise exceptions.InvalidCredentials(
415 'Credentials must be specified')
416 auth_provider_class, auth_url = get_auth_provider_class(
417 credentials)
418 _auth_provider = auth_provider_class(credentials, auth_url,
419 scope=scope,
420 **default_params)
421 if pre_auth:
422 _auth_provider.set_auth()
423 return _auth_provider