blob: f0c41122361a5356fbdbb71968cbfac8f96ae576 [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)de5fb0c2016-06-13 12:15:00 +010024from tempest.lib import exceptions as lib_exc
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
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010042 default_params = config.service_client_config()
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000043
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010044 # TODO(andreaf) This is only used by data_processing and baremetal clients,
45 # and should be removed once they are out of Tempest
Ken'ichi Ohmichi737a6032015-01-21 07:04:42 +000046 default_params_with_timeout_values = {
47 'build_interval': CONF.compute.build_interval,
48 'build_timeout': CONF.compute.build_timeout
49 }
50 default_params_with_timeout_values.update(default_params)
51
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010052 def __init__(self, credentials, service=None, scope='project'):
ghanshyam4e2be342015-11-27 18:07:46 +090053 """Initialization of Manager class.
Brant Knudsonc7ca3342013-03-28 21:08:50 -050054
ghanshyam4e2be342015-11-27 18:07:46 +090055 Setup all services clients and make them available for tests cases.
56 :param credentials: type Credentials or TestResources
57 :param service: Service name
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +010058 :param scope: default scope for tokens produced by the auth provider
ghanshyam4e2be342015-11-27 18:07:46 +090059 """
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +010060 _, identity_uri = get_auth_provider_class(credentials)
61 super(Manager, self).__init__(
62 credentials=credentials, identity_uri=identity_uri, scope=scope,
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010063 region=CONF.identity.region,
64 client_parameters=self._prepare_configuration())
65 # TODO(andreaf) When clients are initialised without the right
66 # parameters available, the calls below will trigger a KeyError.
67 # We should catch that and raise a better error.
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +000068 self._set_compute_clients()
69 self._set_identity_clients()
70 self._set_volume_clients()
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +000071 self._set_object_storage_clients()
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +010072 self._set_image_clients()
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +010073 self._set_network_clients()
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +000074
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010075 self.baremetal_client = baremetal.BaremetalClient(
Ken'ichi Ohmichi1f88ece2015-01-23 03:33:11 +000076 self.auth_provider,
77 CONF.baremetal.catalog_type,
78 CONF.identity.region,
79 endpoint_type=CONF.baremetal.endpoint_type,
80 **self.default_params_with_timeout_values)
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010081 self.orchestration_client = orchestration.OrchestrationClient(
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000082 self.auth_provider,
83 CONF.orchestration.catalog_type,
84 CONF.orchestration.region or CONF.identity.region,
85 endpoint_type=CONF.orchestration.endpoint_type,
86 build_interval=CONF.orchestration.build_interval,
87 build_timeout=CONF.orchestration.build_timeout,
88 **self.default_params)
Andrea Frittoli (andreaf)c33486f2016-06-17 12:22:08 +010089 self.data_processing_client = data_processing.DataProcessingClient(
Ken'ichi Ohmichi4e83b5e2015-02-13 04:07:34 +000090 self.auth_provider,
91 CONF.data_processing.catalog_type,
92 CONF.identity.region,
93 endpoint_type=CONF.data_processing.endpoint_type,
94 **self.default_params_with_timeout_values)
Ken'ichi Ohmichib38eb002015-01-23 02:35:01 +000095 self.negative_client = negative_rest_client.NegativeRestClient(
David Kranz1e33e372015-03-20 09:42:56 -040096 self.auth_provider, service, **self.default_params)
Ken'ichi Ohmichic2b11ce2015-01-16 07:17:29 +000097
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +010098 def _prepare_configuration(self):
99 """Map values from CONF into Manager parameters
100
101 This uses `config.service_client_config` for all services to collect
102 most configuration items needed to init the clients.
103 """
104 # NOTE(andreaf) Configuration items will be passed in future patches
105 # into ClientFactory objects, but for now we update all the
106 # _set_*_client methods to consume them so we can verify that the
107 # configuration collected is correct
108
109 configuration = {}
110
111 # Setup the parameters for all Tempest services.
112 # NOTE(andreaf) Since client.py is an internal module of Tempest,
113 # it doesn't have to consider plugin configuration.
114 for service in service_clients.tempest_modules():
115 try:
116 # NOTE(andreaf) Use the unversioned service name to fetch
117 # the configuration since configuration is not versioned.
118 service_for_config = service.split('.')[0]
119 if service_for_config not in configuration:
120 configuration[service_for_config] = (
121 config.service_client_config(service_for_config))
122 except lib_exc.UnknownServiceClient:
123 LOG.warn(
124 'Could not load configuration for service %s' % service)
125
126 return configuration
127
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100128 def _set_network_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100129 params = self.parameters['network']
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100130 self.network_agents_client = network.AgentsClient(
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.network_extensions_client = network.ExtensionsClient(
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.networks_client = network.NetworksClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100135 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100136 self.subnetpools_client = network.SubnetpoolsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100137 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100138 self.subnets_client = network.SubnetsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100139 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100140 self.ports_client = network.PortsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100141 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100142 self.network_quotas_client = network.QuotasClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100143 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100144 self.floating_ips_client = network.FloatingIPsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100145 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100146 self.metering_labels_client = network.MeteringLabelsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100147 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100148 self.metering_label_rules_client = network.MeteringLabelRulesClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100149 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100150 self.routers_client = network.RoutersClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100151 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100152 self.security_group_rules_client = network.SecurityGroupRulesClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100153 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100154 self.security_groups_client = network.SecurityGroupsClient(
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100155 self.auth_provider, **params)
Andrea Frittoli (andreaf)fa991be2016-06-17 11:46:14 +0100156 self.network_versions_client = network.NetworkVersionsClient(
Mark T. Voelkerabd4cbd2016-04-29 12:03:04 -0500157 self.auth_provider, **params)
Andrea Frittoli (andreaf)11e1e882016-06-07 18:35:58 +0100158
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100159 def _set_image_clients(self):
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100160 if CONF.service_available.glance:
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100161 params = self.parameters['image']
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100162 self.image_client = image.v1.ImagesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100163 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100164 self.image_member_client = image.v1.ImageMembersClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100165 self.auth_provider, **params)
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100166
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100167 self.image_client_v2 = image.v2.ImagesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100168 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100169 self.image_member_client_v2 = image.v2.ImageMembersClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100170 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100171 self.namespaces_client = image.v2.NamespacesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100172 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100173 self.resource_types_client = image.v2.ResourceTypesClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100174 self.auth_provider, **params)
Andrea Frittoli (andreaf)26300f92016-06-17 12:14:00 +0100175 self.schemas_client = image.v2.SchemasClient(
Andrea Frittoli (andreaf)591e8542016-06-07 18:31:39 +0100176 self.auth_provider, **params)
177
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000178 def _set_compute_clients(self):
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100179 self.agents_client = self.compute.AgentsClient()
180 self.compute_networks_client = self.compute.NetworksClient()
181 self.migrations_client = self.compute.MigrationsClient()
Ken'ichi Ohmichi65225ef2014-11-19 01:06:25 +0000182 self.security_group_default_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100183 self.compute.SecurityGroupDefaultRulesClient())
184 self.certificates_client = self.compute.CertificatesClient()
185 eip = CONF.compute_feature_enabled.enable_instance_password
186 self.servers_client = self.compute.ServersClient(
187 enable_instance_password=eip)
188 self.server_groups_client = self.compute.ServerGroupsClient()
189 self.limits_client = self.compute.LimitsClient()
190 self.compute_images_client = self.compute.ImagesClient()
191 self.keypairs_client = self.compute.KeyPairsClient()
192 self.quotas_client = self.compute.QuotasClient()
193 self.quota_classes_client = self.compute.QuotaClassesClient()
194 self.flavors_client = self.compute.FlavorsClient()
195 self.extensions_client = self.compute.ExtensionsClient()
196 self.floating_ip_pools_client = self.compute.FloatingIPPoolsClient()
197 self.floating_ips_bulk_client = self.compute.FloatingIPsBulkClient()
198 self.compute_floating_ips_client = self.compute.FloatingIPsClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100199 self.compute_security_group_rules_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100200 self.compute.SecurityGroupRulesClient())
201 self.compute_security_groups_client = (
202 self.compute.SecurityGroupsClient())
203 self.interfaces_client = self.compute.InterfacesClient()
204 self.fixed_ips_client = self.compute.FixedIPsClient()
205 self.availability_zone_client = self.compute.AvailabilityZoneClient()
206 self.aggregates_client = self.compute.AggregatesClient()
207 self.services_client = self.compute.ServicesClient()
208 self.tenant_usages_client = self.compute.TenantUsagesClient()
209 self.hosts_client = self.compute.HostsClient()
210 self.hypervisor_client = self.compute.HypervisorClient()
Andrea Frittoli (andreaf)76a4b4e2016-06-14 23:28:16 +0100211 self.instance_usages_audit_log_client = (
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100212 self.compute.InstanceUsagesAuditLogClient())
213 self.tenant_networks_client = self.compute.TenantNetworksClient()
214 self.baremetal_nodes_client = self.compute.BaremetalNodesClient()
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +0000215
216 # NOTE: The following client needs special timeout values because
217 # the API is a proxy for the other component.
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100218 params_volume = {}
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100219 for _key in ('build_interval', 'build_timeout'):
220 _value = self.parameters['volume'].get(_key)
221 if _value:
222 params_volume[_key] = _value
Andrea Frittoli (andreaf)142d8192016-07-05 23:19:05 +0100223 self.volumes_extensions_client = self.compute.VolumesClient(
224 **params_volume)
225 self.compute_versions_client = self.compute.VersionsClient(
226 **params_volume)
227 self.snapshots_extensions_client = self.compute.SnapshotsClient(
228 **params_volume)
Ken'ichi Ohmichicd4a51e2014-11-13 07:25:33 +0000229
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000230 def _set_identity_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100231 params = self.parameters['identity']
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300232
233 # Clients below use the admin endpoint type of Keystone API v2
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100234 params_v2_admin = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300235 params_v2_admin['endpoint_type'] = CONF.identity.v2_admin_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100236 self.endpoints_client = identity.v2.EndpointsClient(self.auth_provider,
237 **params_v2_admin)
238 self.identity_client = identity.v2.IdentityClient(self.auth_provider,
239 **params_v2_admin)
240 self.tenants_client = identity.v2.TenantsClient(self.auth_provider,
241 **params_v2_admin)
242 self.roles_client = identity.v2.RolesClient(self.auth_provider,
243 **params_v2_admin)
244 self.users_client = identity.v2.UsersClient(self.auth_provider,
245 **params_v2_admin)
246 self.identity_services_client = identity.v2.ServicesClient(
Yaroslav Lobankovf6906e12016-02-26 19:44:53 -0600247 self.auth_provider, **params_v2_admin)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300248
249 # Clients below use the public endpoint type of Keystone API v2
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100250 params_v2_public = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300251 params_v2_public['endpoint_type'] = (
252 CONF.identity.v2_public_endpoint_type)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100253 self.identity_public_client = identity.v2.IdentityClient(
254 self.auth_provider, **params_v2_public)
255 self.tenants_public_client = identity.v2.TenantsClient(
256 self.auth_provider, **params_v2_public)
257 self.users_public_client = identity.v2.UsersClient(
258 self.auth_provider, **params_v2_public)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300259
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100260 # Clients below use the endpoint type of Keystone API v3, which is set
261 # in endpoint_type
262 params_v3 = copy.copy(params)
Jane Zadorozhnac7862132015-07-10 14:34:50 +0300263 params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100264 self.domains_client = identity.v3.DomainsClient(self.auth_provider,
265 **params_v3)
266 self.identity_v3_client = identity.v3.IdentityClient(
Yaroslav Lobankov69d90562015-12-18 12:06:40 +0300267 self.auth_provider, **params_v3)
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100268 self.trusts_client = identity.v3.TrustsClient(self.auth_provider,
269 **params_v3)
270 self.users_v3_client = identity.v3.UsersClient(self.auth_provider,
271 **params_v3)
272 self.endpoints_v3_client = identity.v3.EndPointsClient(
273 self.auth_provider, **params_v3)
274 self.roles_v3_client = identity.v3.RolesClient(self.auth_provider,
275 **params_v3)
276 self.identity_services_v3_client = identity.v3.ServicesClient(
277 self.auth_provider, **params_v3)
278 self.policies_client = identity.v3.PoliciesClient(self.auth_provider,
279 **params_v3)
280 self.projects_client = identity.v3.ProjectsClient(self.auth_provider,
281 **params_v3)
282 self.regions_client = identity.v3.RegionsClient(self.auth_provider,
283 **params_v3)
284 self.credentials_client = identity.v3.CredentialsClient(
285 self.auth_provider, **params_v3)
286 self.groups_client = identity.v3.GroupsClient(self.auth_provider,
287 **params_v3)
Yaroslav Lobankovcd97fea2016-01-13 19:59:52 +0300288
Andrea Frittoli90012352015-02-25 21:58:02 +0000289 # Token clients do not use the catalog. They only need default_params.
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100290 # They read auth_url, so they should only be set if the corresponding
291 # API version is marked as enabled
292 if CONF.identity_feature_enabled.api_v2:
293 if CONF.identity.uri:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100294 self.token_client = identity.v2.TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100295 CONF.identity.uri, **self.default_params)
296 else:
297 msg = 'Identity v2 API enabled, but no identity.uri set'
298 raise exceptions.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000299 if CONF.identity_feature_enabled.api_v3:
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100300 if CONF.identity.uri_v3:
Andrea Frittoli (andreaf)6cb6b132016-06-17 11:39:10 +0100301 self.token_v3_client = identity.v3.V3TokenClient(
Andrea Frittoli (andreaf)03e546f2015-05-13 12:44:47 +0100302 CONF.identity.uri_v3, **self.default_params)
303 else:
304 msg = 'Identity v3 API enabled, but no identity.uri_v3 set'
305 raise exceptions.InvalidConfiguration(msg)
Ken'ichi Ohmichi41951b02014-11-19 01:57:43 +0000306
Ken'ichi Ohmichi80ec0b92015-01-16 06:43:10 +0000307 def _set_volume_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100308 # Mandatory parameters (always defined)
309 params = self.parameters['volume']
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000310
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100311 self.volume_qos_client = volume.v1.QosSpecsClient(self.auth_provider,
312 **params)
313 self.volume_qos_v2_client = volume.v2.QosSpecsClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000314 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100315 self.volume_services_client = volume.v1.ServicesClient(
Yaroslav Lobankov4c237792015-12-02 18:43:48 +0300316 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100317 self.volume_services_v2_client = volume.v2.ServicesClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000318 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100319 self.backups_client = volume.v1.BackupsClient(self.auth_provider,
320 **params)
321 self.backups_v2_client = volume.v2.BackupsClient(self.auth_provider,
322 **params)
323 self.snapshots_client = volume.v1.SnapshotsClient(self.auth_provider,
324 **params)
325 self.snapshots_v2_client = volume.v2.SnapshotsClient(
326 self.auth_provider, **params)
327 self.volumes_client = volume.v1.VolumesClient(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +0000328 self.auth_provider, default_volume_size=CONF.volume.volume_size,
329 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100330 self.volumes_v2_client = volume.v2.VolumesClient(
Ken'ichi Ohmichi234da802015-02-13 04:48:06 +0000331 self.auth_provider, default_volume_size=CONF.volume.volume_size,
332 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100333 self.volume_messages_client = volume.v3.MessagesClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000334 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100335 self.volume_types_client = volume.v1.TypesClient(self.auth_provider,
336 **params)
337 self.volume_types_v2_client = volume.v2.TypesClient(self.auth_provider,
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000338 **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100339 self.volume_hosts_client = volume.v1.HostsClient(self.auth_provider,
340 **params)
341 self.volume_hosts_v2_client = volume.v2.HostsClient(self.auth_provider,
342 **params)
343 self.volume_quotas_client = volume.v1.QuotasClient(self.auth_provider,
344 **params)
345 self.volume_quotas_v2_client = volume.v2.QuotasClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000346 self.auth_provider, **params)
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100347 self.volumes_extension_client = volume.v1.ExtensionsClient(
348 self.auth_provider, **params)
349 self.volumes_v2_extension_client = volume.v2.ExtensionsClient(
Ken'ichi Ohmichif85e9bd2015-01-27 12:51:47 +0000350 self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000351 self.volume_availability_zone_client = \
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100352 volume.v1.AvailabilityZoneClient(self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000353 self.volume_v2_availability_zone_client = \
Andrea Frittoli (andreaf)14ecae12016-06-17 11:56:24 +0100354 volume.v2.AvailabilityZoneClient(self.auth_provider, **params)
Ken'ichi Ohmichi532ae922014-11-19 01:37:15 +0000355
Ken'ichi Ohmichic95eb852015-01-22 01:57:57 +0000356 def _set_object_storage_clients(self):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100357 # Mandatory parameters (always defined)
358 params = self.parameters['object-storage']
Ken'ichi Ohmichi564b2ad2015-01-22 02:08:59 +0000359
Andrea Frittoli (andreaf)9a225432016-06-17 12:16:22 +0100360 self.account_client = object_storage.AccountClient(self.auth_provider,
361 **params)
362 self.container_client = object_storage.ContainerClient(
363 self.auth_provider, **params)
364 self.object_client = object_storage.ObjectClient(self.auth_provider,
365 **params)
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100366
367
368def get_auth_provider_class(credentials):
369 if isinstance(credentials, auth.KeystoneV3Credentials):
370 return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3
371 else:
372 return auth.KeystoneV2AuthProvider, CONF.identity.uri
373
374
375def get_auth_provider(credentials, pre_auth=False, scope='project'):
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100376 # kwargs for auth provider match the common ones used by service clients
377 default_params = config.service_client_config()
Andrea Frittoli (andreaf)23950142016-06-13 12:39:29 +0100378 if credentials is None:
379 raise exceptions.InvalidCredentials(
380 'Credentials must be specified')
381 auth_provider_class, auth_url = get_auth_provider_class(
382 credentials)
383 _auth_provider = auth_provider_class(credentials, auth_url,
384 scope=scope,
385 **default_params)
386 if pre_auth:
387 _auth_provider.set_auth()
388 return _auth_provider