ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 2 | # 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 Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 16 | import copy |
ChangBo Guo(gcb) | 9f14789 | 2016-09-21 14:01:32 +0800 | [diff] [blame] | 17 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 18 | from oslo_log import log as logging |
ChangBo Guo(gcb) | 9f14789 | 2016-09-21 14:01:32 +0800 | [diff] [blame] | 19 | |
Ken'ichi Ohmichi | 4266268 | 2015-01-05 05:00:04 +0000 | [diff] [blame] | 20 | from tempest.common import negative_rest_client |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 21 | from tempest import config |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 22 | from tempest import exceptions |
Andrea Frittoli (andreaf) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 23 | from tempest.lib import auth |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 24 | from tempest.lib import exceptions as lib_exc |
Andrea Frittoli (andreaf) | e07579c | 2016-08-05 07:27:02 +0100 | [diff] [blame] | 25 | from tempest.lib.services import clients |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 26 | from tempest.services import baremetal |
| 27 | from tempest.services import data_processing |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 28 | from tempest.services import identity |
Andrea Frittoli (andreaf) | 9a22543 | 2016-06-17 12:16:22 +0100 | [diff] [blame] | 29 | from tempest.services import object_storage |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 30 | from tempest.services import orchestration |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 31 | from tempest.services import volume |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 32 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 33 | CONF = config.CONF |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 34 | LOG = logging.getLogger(__name__) |
| 35 | |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 36 | |
Andrea Frittoli (andreaf) | e07579c | 2016-08-05 07:27:02 +0100 | [diff] [blame] | 37 | class Manager(clients.ServiceClients): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 38 | """Top level manager for OpenStack tempest clients""" |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 39 | |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 40 | default_params = config.service_client_config() |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 41 | |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 42 | # TODO(andreaf) This is only used by data_processing and baremetal clients, |
| 43 | # and should be removed once they are out of Tempest |
Ken'ichi Ohmichi | 737a603 | 2015-01-21 07:04:42 +0000 | [diff] [blame] | 44 | default_params_with_timeout_values = { |
| 45 | 'build_interval': CONF.compute.build_interval, |
| 46 | 'build_timeout': CONF.compute.build_timeout |
| 47 | } |
| 48 | default_params_with_timeout_values.update(default_params) |
| 49 | |
Andrea Frittoli (andreaf) | 3e82af7 | 2016-05-05 22:53:38 +0100 | [diff] [blame] | 50 | def __init__(self, credentials, service=None, scope='project'): |
ghanshyam | 4e2be34 | 2015-11-27 18:07:46 +0900 | [diff] [blame] | 51 | """Initialization of Manager class. |
Brant Knudson | c7ca334 | 2013-03-28 21:08:50 -0500 | [diff] [blame] | 52 | |
ghanshyam | 4e2be34 | 2015-11-27 18:07:46 +0900 | [diff] [blame] | 53 | Setup all services clients and make them available for tests cases. |
| 54 | :param credentials: type Credentials or TestResources |
| 55 | :param service: Service name |
Andrea Frittoli (andreaf) | 3e82af7 | 2016-05-05 22:53:38 +0100 | [diff] [blame] | 56 | :param scope: default scope for tokens produced by the auth provider |
ghanshyam | 4e2be34 | 2015-11-27 18:07:46 +0900 | [diff] [blame] | 57 | """ |
Andrea Frittoli (andreaf) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 58 | _, identity_uri = get_auth_provider_class(credentials) |
| 59 | super(Manager, self).__init__( |
| 60 | credentials=credentials, identity_uri=identity_uri, scope=scope, |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 61 | region=CONF.identity.region, |
| 62 | client_parameters=self._prepare_configuration()) |
| 63 | # TODO(andreaf) When clients are initialised without the right |
| 64 | # parameters available, the calls below will trigger a KeyError. |
| 65 | # We should catch that and raise a better error. |
Ken'ichi Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 66 | self._set_compute_clients() |
| 67 | self._set_identity_clients() |
| 68 | self._set_volume_clients() |
Ken'ichi Ohmichi | c95eb85 | 2015-01-22 01:57:57 +0000 | [diff] [blame] | 69 | self._set_object_storage_clients() |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 70 | self._set_image_clients() |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 71 | self._set_network_clients() |
Ken'ichi Ohmichi | cd4a51e | 2014-11-13 07:25:33 +0000 | [diff] [blame] | 72 | |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 73 | self.baremetal_client = baremetal.BaremetalClient( |
Ken'ichi Ohmichi | 1f88ece | 2015-01-23 03:33:11 +0000 | [diff] [blame] | 74 | self.auth_provider, |
| 75 | CONF.baremetal.catalog_type, |
| 76 | CONF.identity.region, |
| 77 | endpoint_type=CONF.baremetal.endpoint_type, |
| 78 | **self.default_params_with_timeout_values) |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 79 | self.orchestration_client = orchestration.OrchestrationClient( |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 80 | self.auth_provider, |
| 81 | CONF.orchestration.catalog_type, |
| 82 | CONF.orchestration.region or CONF.identity.region, |
| 83 | endpoint_type=CONF.orchestration.endpoint_type, |
| 84 | build_interval=CONF.orchestration.build_interval, |
| 85 | build_timeout=CONF.orchestration.build_timeout, |
| 86 | **self.default_params) |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 87 | self.data_processing_client = data_processing.DataProcessingClient( |
Ken'ichi Ohmichi | 4e83b5e | 2015-02-13 04:07:34 +0000 | [diff] [blame] | 88 | self.auth_provider, |
| 89 | CONF.data_processing.catalog_type, |
| 90 | CONF.identity.region, |
| 91 | endpoint_type=CONF.data_processing.endpoint_type, |
| 92 | **self.default_params_with_timeout_values) |
Ken'ichi Ohmichi | b38eb00 | 2015-01-23 02:35:01 +0000 | [diff] [blame] | 93 | self.negative_client = negative_rest_client.NegativeRestClient( |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 94 | self.auth_provider, service, **self.default_params) |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 95 | |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 96 | def _prepare_configuration(self): |
| 97 | """Map values from CONF into Manager parameters |
| 98 | |
| 99 | This uses `config.service_client_config` for all services to collect |
| 100 | most configuration items needed to init the clients. |
| 101 | """ |
Andrea Frittoli (andreaf) | 8420abe | 2016-07-27 11:47:43 +0100 | [diff] [blame] | 102 | # NOTE(andreaf) Once all service clients in Tempest are migrated |
| 103 | # to tempest.lib, their configuration will be picked up from the |
| 104 | # registry, and this method will become redundant. |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 105 | |
| 106 | configuration = {} |
| 107 | |
Andrea Frittoli (andreaf) | 8420abe | 2016-07-27 11:47:43 +0100 | [diff] [blame] | 108 | # Setup the parameters for all Tempest services which are not in lib. |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 109 | # NOTE(andreaf) Since client.py is an internal module of Tempest, |
| 110 | # it doesn't have to consider plugin configuration. |
Andrea Frittoli (andreaf) | 8420abe | 2016-07-27 11:47:43 +0100 | [diff] [blame] | 111 | for service in clients._tempest_internal_modules(): |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 112 | try: |
| 113 | # NOTE(andreaf) Use the unversioned service name to fetch |
| 114 | # the configuration since configuration is not versioned. |
| 115 | service_for_config = service.split('.')[0] |
| 116 | if service_for_config not in configuration: |
| 117 | configuration[service_for_config] = ( |
| 118 | config.service_client_config(service_for_config)) |
| 119 | except lib_exc.UnknownServiceClient: |
Cao Xuan Hoang | 738ffcb | 2016-09-26 15:35:23 +0700 | [diff] [blame^] | 120 | LOG.warning( |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 121 | 'Could not load configuration for service %s' % service) |
| 122 | |
| 123 | return configuration |
| 124 | |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 125 | def _set_network_clients(self): |
Andrea Frittoli (andreaf) | 127c102 | 2016-07-05 23:19:50 +0100 | [diff] [blame] | 126 | self.network_agents_client = self.network.AgentsClient() |
| 127 | self.network_extensions_client = self.network.ExtensionsClient() |
| 128 | self.networks_client = self.network.NetworksClient() |
| 129 | self.subnetpools_client = self.network.SubnetpoolsClient() |
| 130 | self.subnets_client = self.network.SubnetsClient() |
| 131 | self.ports_client = self.network.PortsClient() |
| 132 | self.network_quotas_client = self.network.QuotasClient() |
| 133 | self.floating_ips_client = self.network.FloatingIPsClient() |
| 134 | self.metering_labels_client = self.network.MeteringLabelsClient() |
| 135 | self.metering_label_rules_client = ( |
| 136 | self.network.MeteringLabelRulesClient()) |
| 137 | self.routers_client = self.network.RoutersClient() |
| 138 | self.security_group_rules_client = ( |
| 139 | self.network.SecurityGroupRulesClient()) |
| 140 | self.security_groups_client = self.network.SecurityGroupsClient() |
| 141 | self.network_versions_client = self.network.NetworkVersionsClient() |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 142 | |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 143 | def _set_image_clients(self): |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 144 | if CONF.service_available.glance: |
Andrea Frittoli (andreaf) | e6a9b3f | 2016-06-30 16:24:32 +0100 | [diff] [blame] | 145 | self.image_client = self.image_v1.ImagesClient() |
| 146 | self.image_member_client = self.image_v1.ImageMembersClient() |
| 147 | self.image_client_v2 = self.image_v2.ImagesClient() |
| 148 | self.image_member_client_v2 = self.image_v2.ImageMembersClient() |
| 149 | self.namespaces_client = self.image_v2.NamespacesClient() |
| 150 | self.resource_types_client = self.image_v2.ResourceTypesClient() |
| 151 | self.schemas_client = self.image_v2.SchemasClient() |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 152 | |
Ken'ichi Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 153 | def _set_compute_clients(self): |
Andrea Frittoli (andreaf) | 142d819 | 2016-07-05 23:19:05 +0100 | [diff] [blame] | 154 | self.agents_client = self.compute.AgentsClient() |
| 155 | self.compute_networks_client = self.compute.NetworksClient() |
| 156 | self.migrations_client = self.compute.MigrationsClient() |
Ken'ichi Ohmichi | 65225ef | 2014-11-19 01:06:25 +0000 | [diff] [blame] | 157 | self.security_group_default_rules_client = ( |
Andrea Frittoli (andreaf) | 142d819 | 2016-07-05 23:19:05 +0100 | [diff] [blame] | 158 | self.compute.SecurityGroupDefaultRulesClient()) |
| 159 | self.certificates_client = self.compute.CertificatesClient() |
| 160 | eip = CONF.compute_feature_enabled.enable_instance_password |
| 161 | self.servers_client = self.compute.ServersClient( |
| 162 | enable_instance_password=eip) |
| 163 | self.server_groups_client = self.compute.ServerGroupsClient() |
| 164 | self.limits_client = self.compute.LimitsClient() |
| 165 | self.compute_images_client = self.compute.ImagesClient() |
| 166 | self.keypairs_client = self.compute.KeyPairsClient() |
| 167 | self.quotas_client = self.compute.QuotasClient() |
| 168 | self.quota_classes_client = self.compute.QuotaClassesClient() |
| 169 | self.flavors_client = self.compute.FlavorsClient() |
| 170 | self.extensions_client = self.compute.ExtensionsClient() |
| 171 | self.floating_ip_pools_client = self.compute.FloatingIPPoolsClient() |
| 172 | self.floating_ips_bulk_client = self.compute.FloatingIPsBulkClient() |
| 173 | self.compute_floating_ips_client = self.compute.FloatingIPsClient() |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 174 | self.compute_security_group_rules_client = ( |
Andrea Frittoli (andreaf) | 142d819 | 2016-07-05 23:19:05 +0100 | [diff] [blame] | 175 | self.compute.SecurityGroupRulesClient()) |
| 176 | self.compute_security_groups_client = ( |
| 177 | self.compute.SecurityGroupsClient()) |
| 178 | self.interfaces_client = self.compute.InterfacesClient() |
| 179 | self.fixed_ips_client = self.compute.FixedIPsClient() |
| 180 | self.availability_zone_client = self.compute.AvailabilityZoneClient() |
| 181 | self.aggregates_client = self.compute.AggregatesClient() |
| 182 | self.services_client = self.compute.ServicesClient() |
| 183 | self.tenant_usages_client = self.compute.TenantUsagesClient() |
| 184 | self.hosts_client = self.compute.HostsClient() |
| 185 | self.hypervisor_client = self.compute.HypervisorClient() |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 186 | self.instance_usages_audit_log_client = ( |
Andrea Frittoli (andreaf) | 142d819 | 2016-07-05 23:19:05 +0100 | [diff] [blame] | 187 | self.compute.InstanceUsagesAuditLogClient()) |
| 188 | self.tenant_networks_client = self.compute.TenantNetworksClient() |
| 189 | self.baremetal_nodes_client = self.compute.BaremetalNodesClient() |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 190 | |
| 191 | # NOTE: The following client needs special timeout values because |
| 192 | # the API is a proxy for the other component. |
Andrea Frittoli (andreaf) | 142d819 | 2016-07-05 23:19:05 +0100 | [diff] [blame] | 193 | params_volume = {} |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 194 | for _key in ('build_interval', 'build_timeout'): |
| 195 | _value = self.parameters['volume'].get(_key) |
| 196 | if _value: |
| 197 | params_volume[_key] = _value |
Andrea Frittoli (andreaf) | 142d819 | 2016-07-05 23:19:05 +0100 | [diff] [blame] | 198 | self.volumes_extensions_client = self.compute.VolumesClient( |
| 199 | **params_volume) |
| 200 | self.compute_versions_client = self.compute.VersionsClient( |
| 201 | **params_volume) |
| 202 | self.snapshots_extensions_client = self.compute.SnapshotsClient( |
| 203 | **params_volume) |
Ken'ichi Ohmichi | cd4a51e | 2014-11-13 07:25:33 +0000 | [diff] [blame] | 204 | |
Ken'ichi Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 205 | def _set_identity_clients(self): |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 206 | params = self.parameters['identity'] |
Yaroslav Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 207 | |
| 208 | # Clients below use the admin endpoint type of Keystone API v2 |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 209 | params_v2_admin = copy.copy(params) |
Jane Zadorozhna | c786213 | 2015-07-10 14:34:50 +0300 | [diff] [blame] | 210 | params_v2_admin['endpoint_type'] = CONF.identity.v2_admin_endpoint_type |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 211 | self.endpoints_client = identity.v2.EndpointsClient(self.auth_provider, |
| 212 | **params_v2_admin) |
| 213 | self.identity_client = identity.v2.IdentityClient(self.auth_provider, |
| 214 | **params_v2_admin) |
| 215 | self.tenants_client = identity.v2.TenantsClient(self.auth_provider, |
| 216 | **params_v2_admin) |
| 217 | self.roles_client = identity.v2.RolesClient(self.auth_provider, |
| 218 | **params_v2_admin) |
| 219 | self.users_client = identity.v2.UsersClient(self.auth_provider, |
| 220 | **params_v2_admin) |
| 221 | self.identity_services_client = identity.v2.ServicesClient( |
Yaroslav Lobankov | f6906e1 | 2016-02-26 19:44:53 -0600 | [diff] [blame] | 222 | self.auth_provider, **params_v2_admin) |
Yaroslav Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 223 | |
| 224 | # Clients below use the public endpoint type of Keystone API v2 |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 225 | params_v2_public = copy.copy(params) |
Jane Zadorozhna | c786213 | 2015-07-10 14:34:50 +0300 | [diff] [blame] | 226 | params_v2_public['endpoint_type'] = ( |
| 227 | CONF.identity.v2_public_endpoint_type) |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 228 | self.identity_public_client = identity.v2.IdentityClient( |
| 229 | self.auth_provider, **params_v2_public) |
| 230 | self.tenants_public_client = identity.v2.TenantsClient( |
| 231 | self.auth_provider, **params_v2_public) |
| 232 | self.users_public_client = identity.v2.UsersClient( |
| 233 | self.auth_provider, **params_v2_public) |
Yaroslav Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 234 | |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 235 | # Clients below use the endpoint type of Keystone API v3, which is set |
| 236 | # in endpoint_type |
| 237 | params_v3 = copy.copy(params) |
Jane Zadorozhna | c786213 | 2015-07-10 14:34:50 +0300 | [diff] [blame] | 238 | params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 239 | self.domains_client = identity.v3.DomainsClient(self.auth_provider, |
| 240 | **params_v3) |
| 241 | self.identity_v3_client = identity.v3.IdentityClient( |
Yaroslav Lobankov | 69d9056 | 2015-12-18 12:06:40 +0300 | [diff] [blame] | 242 | self.auth_provider, **params_v3) |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 243 | self.trusts_client = identity.v3.TrustsClient(self.auth_provider, |
| 244 | **params_v3) |
| 245 | self.users_v3_client = identity.v3.UsersClient(self.auth_provider, |
| 246 | **params_v3) |
| 247 | self.endpoints_v3_client = identity.v3.EndPointsClient( |
| 248 | self.auth_provider, **params_v3) |
| 249 | self.roles_v3_client = identity.v3.RolesClient(self.auth_provider, |
| 250 | **params_v3) |
ghanshyam | ad55eb8 | 2016-09-06 13:58:29 +0900 | [diff] [blame] | 251 | self.inherited_roles_client = identity.v3.InheritedRolesClient( |
| 252 | self.auth_provider, **params_v3) |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 253 | self.identity_services_v3_client = identity.v3.ServicesClient( |
| 254 | self.auth_provider, **params_v3) |
| 255 | self.policies_client = identity.v3.PoliciesClient(self.auth_provider, |
| 256 | **params_v3) |
| 257 | self.projects_client = identity.v3.ProjectsClient(self.auth_provider, |
| 258 | **params_v3) |
| 259 | self.regions_client = identity.v3.RegionsClient(self.auth_provider, |
| 260 | **params_v3) |
| 261 | self.credentials_client = identity.v3.CredentialsClient( |
| 262 | self.auth_provider, **params_v3) |
| 263 | self.groups_client = identity.v3.GroupsClient(self.auth_provider, |
| 264 | **params_v3) |
Yaroslav Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 265 | |
Andrea Frittoli | 9001235 | 2015-02-25 21:58:02 +0000 | [diff] [blame] | 266 | # Token clients do not use the catalog. They only need default_params. |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 267 | # They read auth_url, so they should only be set if the corresponding |
| 268 | # API version is marked as enabled |
| 269 | if CONF.identity_feature_enabled.api_v2: |
| 270 | if CONF.identity.uri: |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 271 | self.token_client = identity.v2.TokenClient( |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 272 | CONF.identity.uri, **self.default_params) |
| 273 | else: |
| 274 | msg = 'Identity v2 API enabled, but no identity.uri set' |
| 275 | raise exceptions.InvalidConfiguration(msg) |
Ken'ichi Ohmichi | 41951b0 | 2014-11-19 01:57:43 +0000 | [diff] [blame] | 276 | if CONF.identity_feature_enabled.api_v3: |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 277 | if CONF.identity.uri_v3: |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 278 | self.token_v3_client = identity.v3.V3TokenClient( |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 279 | CONF.identity.uri_v3, **self.default_params) |
| 280 | else: |
| 281 | msg = 'Identity v3 API enabled, but no identity.uri_v3 set' |
| 282 | raise exceptions.InvalidConfiguration(msg) |
Ken'ichi Ohmichi | 41951b0 | 2014-11-19 01:57:43 +0000 | [diff] [blame] | 283 | |
Ken'ichi Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 284 | def _set_volume_clients(self): |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 285 | # Mandatory parameters (always defined) |
| 286 | params = self.parameters['volume'] |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 287 | |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 288 | self.volume_qos_client = volume.v1.QosSpecsClient(self.auth_provider, |
| 289 | **params) |
| 290 | self.volume_qos_v2_client = volume.v2.QosSpecsClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 291 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 292 | self.volume_services_client = volume.v1.ServicesClient( |
Yaroslav Lobankov | 4c23779 | 2015-12-02 18:43:48 +0300 | [diff] [blame] | 293 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 294 | self.volume_services_v2_client = volume.v2.ServicesClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 295 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 296 | self.backups_client = volume.v1.BackupsClient(self.auth_provider, |
| 297 | **params) |
| 298 | self.backups_v2_client = volume.v2.BackupsClient(self.auth_provider, |
| 299 | **params) |
Ken'ichi Ohmichi | a6ebf62 | 2016-08-25 11:52:27 -0700 | [diff] [blame] | 300 | self.encryption_types_client = volume.v1.EncryptionTypesClient( |
| 301 | self.auth_provider, **params) |
| 302 | self.encryption_types_v2_client = volume.v2.EncryptionTypesClient( |
| 303 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 304 | self.snapshots_client = volume.v1.SnapshotsClient(self.auth_provider, |
| 305 | **params) |
| 306 | self.snapshots_v2_client = volume.v2.SnapshotsClient( |
| 307 | self.auth_provider, **params) |
Ken'ichi Ohmichi | adb905e | 2016-08-26 15:16:23 -0700 | [diff] [blame] | 308 | self.volumes_client = volume.v1.VolumesClient(self.auth_provider, |
| 309 | **params) |
| 310 | self.volumes_v2_client = volume.v2.VolumesClient(self.auth_provider, |
| 311 | **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 312 | self.volume_messages_client = volume.v3.MessagesClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 313 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 314 | self.volume_types_client = volume.v1.TypesClient(self.auth_provider, |
| 315 | **params) |
| 316 | self.volume_types_v2_client = volume.v2.TypesClient(self.auth_provider, |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 317 | **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 318 | self.volume_hosts_client = volume.v1.HostsClient(self.auth_provider, |
| 319 | **params) |
| 320 | self.volume_hosts_v2_client = volume.v2.HostsClient(self.auth_provider, |
| 321 | **params) |
| 322 | self.volume_quotas_client = volume.v1.QuotasClient(self.auth_provider, |
| 323 | **params) |
| 324 | self.volume_quotas_v2_client = volume.v2.QuotasClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 325 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 326 | self.volumes_extension_client = volume.v1.ExtensionsClient( |
| 327 | self.auth_provider, **params) |
| 328 | self.volumes_v2_extension_client = volume.v2.ExtensionsClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 329 | self.auth_provider, **params) |
Ken'ichi Ohmichi | 532ae92 | 2014-11-19 01:37:15 +0000 | [diff] [blame] | 330 | self.volume_availability_zone_client = \ |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 331 | volume.v1.AvailabilityZoneClient(self.auth_provider, **params) |
Ken'ichi Ohmichi | 532ae92 | 2014-11-19 01:37:15 +0000 | [diff] [blame] | 332 | self.volume_v2_availability_zone_client = \ |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 333 | volume.v2.AvailabilityZoneClient(self.auth_provider, **params) |
Ken'ichi Ohmichi | 532ae92 | 2014-11-19 01:37:15 +0000 | [diff] [blame] | 334 | |
Ken'ichi Ohmichi | c95eb85 | 2015-01-22 01:57:57 +0000 | [diff] [blame] | 335 | def _set_object_storage_clients(self): |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 336 | # Mandatory parameters (always defined) |
| 337 | params = self.parameters['object-storage'] |
Ken'ichi Ohmichi | 564b2ad | 2015-01-22 02:08:59 +0000 | [diff] [blame] | 338 | |
Andrea Frittoli (andreaf) | 9a22543 | 2016-06-17 12:16:22 +0100 | [diff] [blame] | 339 | self.account_client = object_storage.AccountClient(self.auth_provider, |
| 340 | **params) |
| 341 | self.container_client = object_storage.ContainerClient( |
| 342 | self.auth_provider, **params) |
| 343 | self.object_client = object_storage.ObjectClient(self.auth_provider, |
| 344 | **params) |
Andrea Frittoli (andreaf) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 345 | |
| 346 | |
| 347 | def get_auth_provider_class(credentials): |
| 348 | if isinstance(credentials, auth.KeystoneV3Credentials): |
| 349 | return auth.KeystoneV3AuthProvider, CONF.identity.uri_v3 |
| 350 | else: |
| 351 | return auth.KeystoneV2AuthProvider, CONF.identity.uri |
| 352 | |
| 353 | |
| 354 | def get_auth_provider(credentials, pre_auth=False, scope='project'): |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 355 | # kwargs for auth provider match the common ones used by service clients |
| 356 | default_params = config.service_client_config() |
Andrea Frittoli (andreaf) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 357 | if credentials is None: |
| 358 | raise exceptions.InvalidCredentials( |
| 359 | 'Credentials must be specified') |
| 360 | auth_provider_class, auth_url = get_auth_provider_class( |
| 361 | credentials) |
| 362 | _auth_provider = auth_provider_class(credentials, auth_url, |
| 363 | scope=scope, |
| 364 | **default_params) |
| 365 | if pre_auth: |
| 366 | _auth_provider.set_auth() |
| 367 | return _auth_provider |