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 |
| 17 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 18 | from oslo_log import log as logging |
| 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) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 24 | from tempest.lib.services import compute |
Ken'ichi Ohmichi | 4172101 | 2016-06-22 10:41:26 -0700 | [diff] [blame] | 25 | from tempest.lib.services import image |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 26 | from tempest.lib.services import network |
Andrea Frittoli (andreaf) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 27 | from tempest import service_clients |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 28 | from tempest.services import baremetal |
| 29 | from tempest.services import data_processing |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 30 | from tempest.services import identity |
Andrea Frittoli (andreaf) | 9a22543 | 2016-06-17 12:16:22 +0100 | [diff] [blame] | 31 | from tempest.services import object_storage |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 32 | from tempest.services import orchestration |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 33 | from tempest.services import volume |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 34 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 35 | CONF = config.CONF |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 36 | LOG = logging.getLogger(__name__) |
| 37 | |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 38 | |
Andrea Frittoli (andreaf) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 39 | class Manager(service_clients.ServiceClients): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 40 | """Top level manager for OpenStack tempest clients""" |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 41 | |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 42 | 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 Ohmichi | 737a603 | 2015-01-21 07:04:42 +0000 | [diff] [blame] | 49 | # 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) | 3e82af7 | 2016-05-05 22:53:38 +0100 | [diff] [blame] | 57 | def __init__(self, credentials, service=None, scope='project'): |
ghanshyam | 4e2be34 | 2015-11-27 18:07:46 +0900 | [diff] [blame] | 58 | """Initialization of Manager class. |
Brant Knudson | c7ca334 | 2013-03-28 21:08:50 -0500 | [diff] [blame] | 59 | |
ghanshyam | 4e2be34 | 2015-11-27 18:07:46 +0900 | [diff] [blame] | 60 | 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) | 3e82af7 | 2016-05-05 22:53:38 +0100 | [diff] [blame] | 63 | :param scope: default scope for tokens produced by the auth provider |
ghanshyam | 4e2be34 | 2015-11-27 18:07:46 +0900 | [diff] [blame] | 64 | """ |
Andrea Frittoli (andreaf) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 65 | _, 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 Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 69 | self._set_compute_clients() |
| 70 | self._set_identity_clients() |
| 71 | self._set_volume_clients() |
Ken'ichi Ohmichi | c95eb85 | 2015-01-22 01:57:57 +0000 | [diff] [blame] | 72 | self._set_object_storage_clients() |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 73 | self._set_image_clients() |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 74 | self._set_network_clients() |
Ken'ichi Ohmichi | cd4a51e | 2014-11-13 07:25:33 +0000 | [diff] [blame] | 75 | |
Andrea Frittoli (andreaf) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 76 | self.baremetal_client = baremetal.BaremetalClient( |
Ken'ichi Ohmichi | 1f88ece | 2015-01-23 03:33:11 +0000 | [diff] [blame] | 77 | 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) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 82 | self.orchestration_client = orchestration.OrchestrationClient( |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 83 | 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) | c33486f | 2016-06-17 12:22:08 +0100 | [diff] [blame] | 90 | self.data_processing_client = data_processing.DataProcessingClient( |
Ken'ichi Ohmichi | 4e83b5e | 2015-02-13 04:07:34 +0000 | [diff] [blame] | 91 | 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 Ohmichi | b38eb00 | 2015-01-23 02:35:01 +0000 | [diff] [blame] | 96 | self.negative_client = negative_rest_client.NegativeRestClient( |
David Kranz | 1e33e37 | 2015-03-20 09:42:56 -0400 | [diff] [blame] | 97 | self.auth_provider, service, **self.default_params) |
Ken'ichi Ohmichi | c2b11ce | 2015-01-16 07:17:29 +0000 | [diff] [blame] | 98 | |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 99 | 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) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 108 | self.network_agents_client = network.AgentsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 109 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 110 | self.network_extensions_client = network.ExtensionsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 111 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 112 | self.networks_client = network.NetworksClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 113 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 114 | self.subnetpools_client = network.SubnetpoolsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 115 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 116 | self.subnets_client = network.SubnetsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 117 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 118 | self.ports_client = network.PortsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 119 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 120 | self.network_quotas_client = network.QuotasClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 121 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 122 | self.floating_ips_client = network.FloatingIPsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 123 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 124 | self.metering_labels_client = network.MeteringLabelsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 125 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 126 | self.metering_label_rules_client = network.MeteringLabelRulesClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 127 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 128 | self.routers_client = network.RoutersClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 129 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 130 | self.security_group_rules_client = network.SecurityGroupRulesClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 131 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 132 | self.security_groups_client = network.SecurityGroupsClient( |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 133 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | fa991be | 2016-06-17 11:46:14 +0100 | [diff] [blame] | 134 | self.network_versions_client = network.NetworkVersionsClient( |
Mark T. Voelker | abd4cbd | 2016-04-29 12:03:04 -0500 | [diff] [blame] | 135 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 11e1e88 | 2016-06-07 18:35:58 +0100 | [diff] [blame] | 136 | |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 137 | 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) | 26300f9 | 2016-06-17 12:14:00 +0100 | [diff] [blame] | 148 | self.image_client = image.v1.ImagesClient( |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 149 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 26300f9 | 2016-06-17 12:14:00 +0100 | [diff] [blame] | 150 | self.image_member_client = image.v1.ImageMembersClient( |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 151 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 26300f9 | 2016-06-17 12:14:00 +0100 | [diff] [blame] | 152 | self.image_client_v2 = image.v2.ImagesClient( |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 153 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 26300f9 | 2016-06-17 12:14:00 +0100 | [diff] [blame] | 154 | self.image_member_client_v2 = image.v2.ImageMembersClient( |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 155 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 26300f9 | 2016-06-17 12:14:00 +0100 | [diff] [blame] | 156 | self.namespaces_client = image.v2.NamespacesClient( |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 157 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 26300f9 | 2016-06-17 12:14:00 +0100 | [diff] [blame] | 158 | self.resource_types_client = image.v2.ResourceTypesClient( |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 159 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 26300f9 | 2016-06-17 12:14:00 +0100 | [diff] [blame] | 160 | self.schemas_client = image.v2.SchemasClient( |
Andrea Frittoli (andreaf) | 591e854 | 2016-06-07 18:31:39 +0100 | [diff] [blame] | 161 | self.auth_provider, **params) |
| 162 | |
Ken'ichi Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 163 | def _set_compute_clients(self): |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 164 | 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) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 173 | self.agents_client = compute.AgentsClient(self.auth_provider, **params) |
| 174 | self.compute_networks_client = compute.NetworksClient( |
John Warren | 9487a18 | 2015-09-14 18:12:56 -0400 | [diff] [blame] | 175 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 176 | self.migrations_client = compute.MigrationsClient(self.auth_provider, |
| 177 | **params) |
Ken'ichi Ohmichi | 65225ef | 2014-11-19 01:06:25 +0000 | [diff] [blame] | 178 | self.security_group_default_rules_client = ( |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 179 | 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 Igawa | 8f9c0c8 | 2015-03-03 09:38:08 +0900 | [diff] [blame] | 184 | self.auth_provider, |
| 185 | enable_instance_password=CONF.compute_feature_enabled |
| 186 | .enable_instance_password, |
| 187 | **params) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 188 | self.server_groups_client = compute.ServerGroupsClient( |
Ken'ichi Ohmichi | 7ca54b8 | 2015-07-07 01:10:26 +0000 | [diff] [blame] | 189 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 190 | 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 Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 215 | **params) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 216 | self.availability_zone_client = compute.AvailabilityZoneClient( |
Ken'ichi Ohmichi | 03af1c5 | 2015-07-13 00:28:05 +0000 | [diff] [blame] | 217 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 218 | 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 Ohmichi | 2b26e75 | 2015-07-13 00:44:36 +0000 | [diff] [blame] | 223 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 224 | 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 Warren | e74890a | 2015-11-11 15:18:01 -0500 | [diff] [blame] | 230 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 231 | self.baremetal_nodes_client = compute.BaremetalNodesClient( |
YuikoTakada | ac0879a | 2015-01-22 02:40:03 +0000 | [diff] [blame] | 232 | self.auth_provider, **params) |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 233 | |
| 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) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 241 | self.volumes_extensions_client = compute.VolumesClient( |
Ken'ichi Ohmichi | c492178 | 2015-08-05 08:14:42 +0000 | [diff] [blame] | 242 | self.auth_provider, **params_volume) |
Andrea Frittoli (andreaf) | 76a4b4e | 2016-06-14 23:28:16 +0100 | [diff] [blame] | 243 | self.compute_versions_client = compute.VersionsClient( |
| 244 | self.auth_provider, **params_volume) |
| 245 | self.snapshots_extensions_client = compute.SnapshotsClient( |
Gaozexu | b9c9d6e | 2015-09-10 17:08:04 +0800 | [diff] [blame] | 246 | self.auth_provider, **params_volume) |
Ken'ichi Ohmichi | cd4a51e | 2014-11-13 07:25:33 +0000 | [diff] [blame] | 247 | |
Ken'ichi Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 248 | def _set_identity_clients(self): |
ghanshyam | d26b5cd | 2015-02-09 14:48:58 +0900 | [diff] [blame] | 249 | params = { |
| 250 | 'service': CONF.identity.catalog_type, |
Jane Zadorozhna | c786213 | 2015-07-10 14:34:50 +0300 | [diff] [blame] | 251 | 'region': CONF.identity.region |
ghanshyam | d26b5cd | 2015-02-09 14:48:58 +0900 | [diff] [blame] | 252 | } |
| 253 | params.update(self.default_params_with_timeout_values) |
Yaroslav Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 254 | |
| 255 | # Clients below use the admin endpoint type of Keystone API v2 |
Jane Zadorozhna | c786213 | 2015-07-10 14:34:50 +0300 | [diff] [blame] | 256 | params_v2_admin = params.copy() |
| 257 | params_v2_admin['endpoint_type'] = CONF.identity.v2_admin_endpoint_type |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 258 | 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 Lobankov | f6906e1 | 2016-02-26 19:44:53 -0600 | [diff] [blame] | 269 | self.auth_provider, **params_v2_admin) |
Yaroslav Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 270 | |
| 271 | # Clients below use the public endpoint type of Keystone API v2 |
Jane Zadorozhna | c786213 | 2015-07-10 14:34:50 +0300 | [diff] [blame] | 272 | params_v2_public = params.copy() |
| 273 | params_v2_public['endpoint_type'] = ( |
| 274 | CONF.identity.v2_public_endpoint_type) |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 275 | 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 Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 281 | |
| 282 | # Clients below use the endpoint type of Keystone API v3 |
Jane Zadorozhna | c786213 | 2015-07-10 14:34:50 +0300 | [diff] [blame] | 283 | params_v3 = params.copy() |
| 284 | params_v3['endpoint_type'] = CONF.identity.v3_endpoint_type |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 285 | self.domains_client = identity.v3.DomainsClient(self.auth_provider, |
| 286 | **params_v3) |
| 287 | self.identity_v3_client = identity.v3.IdentityClient( |
Yaroslav Lobankov | 69d9056 | 2015-12-18 12:06:40 +0300 | [diff] [blame] | 288 | self.auth_provider, **params_v3) |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 289 | 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 Lobankov | cd97fea | 2016-01-13 19:59:52 +0300 | [diff] [blame] | 309 | |
Andrea Frittoli | 9001235 | 2015-02-25 21:58:02 +0000 | [diff] [blame] | 310 | # 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] | 311 | # 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) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 315 | self.token_client = identity.v2.TokenClient( |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 316 | 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 Ohmichi | 41951b0 | 2014-11-19 01:57:43 +0000 | [diff] [blame] | 320 | if CONF.identity_feature_enabled.api_v3: |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 321 | if CONF.identity.uri_v3: |
Andrea Frittoli (andreaf) | 6cb6b13 | 2016-06-17 11:39:10 +0100 | [diff] [blame] | 322 | self.token_v3_client = identity.v3.V3TokenClient( |
Andrea Frittoli (andreaf) | 03e546f | 2015-05-13 12:44:47 +0100 | [diff] [blame] | 323 | 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 Ohmichi | 41951b0 | 2014-11-19 01:57:43 +0000 | [diff] [blame] | 327 | |
Ken'ichi Ohmichi | 80ec0b9 | 2015-01-16 06:43:10 +0000 | [diff] [blame] | 328 | def _set_volume_clients(self): |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 329 | 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) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 338 | self.volume_qos_client = volume.v1.QosSpecsClient(self.auth_provider, |
| 339 | **params) |
| 340 | self.volume_qos_v2_client = volume.v2.QosSpecsClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 341 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 342 | self.volume_services_client = volume.v1.ServicesClient( |
Yaroslav Lobankov | 4c23779 | 2015-12-02 18:43:48 +0300 | [diff] [blame] | 343 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 344 | self.volume_services_v2_client = volume.v2.ServicesClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 345 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 346 | 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 Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 355 | self.auth_provider, default_volume_size=CONF.volume.volume_size, |
| 356 | **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 357 | self.volumes_v2_client = volume.v2.VolumesClient( |
Ken'ichi Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 358 | self.auth_provider, default_volume_size=CONF.volume.volume_size, |
| 359 | **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 360 | self.volume_messages_client = volume.v3.MessagesClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 361 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 362 | 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 Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 365 | **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 366 | 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 Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 373 | self.auth_provider, **params) |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 374 | self.volumes_extension_client = volume.v1.ExtensionsClient( |
| 375 | self.auth_provider, **params) |
| 376 | self.volumes_v2_extension_client = volume.v2.ExtensionsClient( |
Ken'ichi Ohmichi | f85e9bd | 2015-01-27 12:51:47 +0000 | [diff] [blame] | 377 | self.auth_provider, **params) |
Ken'ichi Ohmichi | 532ae92 | 2014-11-19 01:37:15 +0000 | [diff] [blame] | 378 | self.volume_availability_zone_client = \ |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 379 | volume.v1.AvailabilityZoneClient(self.auth_provider, **params) |
Ken'ichi Ohmichi | 532ae92 | 2014-11-19 01:37:15 +0000 | [diff] [blame] | 380 | self.volume_v2_availability_zone_client = \ |
Andrea Frittoli (andreaf) | 14ecae1 | 2016-06-17 11:56:24 +0100 | [diff] [blame] | 381 | volume.v2.AvailabilityZoneClient(self.auth_provider, **params) |
Ken'ichi Ohmichi | 532ae92 | 2014-11-19 01:37:15 +0000 | [diff] [blame] | 382 | |
Ken'ichi Ohmichi | c95eb85 | 2015-01-22 01:57:57 +0000 | [diff] [blame] | 383 | def _set_object_storage_clients(self): |
Ken'ichi Ohmichi | 564b2ad | 2015-01-22 02:08:59 +0000 | [diff] [blame] | 384 | 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) | 9a22543 | 2016-06-17 12:16:22 +0100 | [diff] [blame] | 391 | 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) | 2395014 | 2016-06-13 12:39:29 +0100 | [diff] [blame] | 397 | |
| 398 | |
| 399 | def 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 | |
| 406 | def 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 |