blob: 48948ea80b1edf7cdc562ff6ae8a2ce98ee88042 [file] [log] [blame]
Jay Pipes3f981df2012-03-27 18:59:44 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes3f981df2012-03-27 18:59:44 -04004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Jay Pipesf38eaac2012-06-21 13:37:35 -040018from tempest import config
Daryl Walleck587385b2012-03-03 13:00:26 -060019from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040020from tempest.openstack.common import log as logging
Attila Fazekas1aed6202013-02-11 14:47:45 +010021from tempest.services import botoclients
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090022from tempest.services.compute.json.aggregates_client import \
23 AggregatesClientJSON
Leo Toyodaa5278912013-04-16 15:40:12 +090024from tempest.services.compute.json.availability_zone_client import \
25 AvailabilityZoneClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050026from tempest.services.compute.json.extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053027 ExtensionsClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040028from tempest.services.compute.json.fixed_ips_client import FixedIPsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050029from tempest.services.compute.json.flavors_client import FlavorsClientJSON
30from tempest.services.compute.json.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053031 FloatingIPsClientJSON
Attila Fazekas8e99b992013-02-24 09:53:23 +010032from tempest.services.compute.json.hosts_client import HostsClientJSON
Tony Yang3d5f1632013-06-06 14:17:57 +080033from tempest.services.compute.json.hypervisor_client import \
34 HypervisorClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050035from tempest.services.compute.json.images_client import ImagesClientJSON
ivan-zhuef7a1bd2013-10-22 17:56:46 +080036from tempest.services.compute.json.instance_usage_audit_log_client import \
37 InstanceUsagesAuditLogClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040038from tempest.services.compute.json.interfaces_client import \
39 InterfacesClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010040from tempest.services.compute.json.keypairs_client import KeyPairsClientJSON
dwallecke62b9f02012-10-10 23:34:42 -050041from tempest.services.compute.json.limits_client import LimitsClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010042from tempest.services.compute.json.quotas_client import QuotasClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050043from tempest.services.compute.json.security_groups_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053044 SecurityGroupsClientJSON
Attila Fazekas6968dd52013-02-15 17:05:53 +010045from tempest.services.compute.json.servers_client import ServersClientJSON
Leo Toyoda3ae31e12013-04-19 11:19:57 +090046from tempest.services.compute.json.services_client import ServicesClientJSON
Leo Toyodad80b6a02013-05-08 12:15:13 +090047from tempest.services.compute.json.tenant_usages_client import \
48 TenantUsagesClientJSON
Matthew Treinisha83a16e2012-12-07 13:44:02 -050049from tempest.services.compute.json.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053050 VolumesExtensionsClientJSON
Mitsuhiko Yamazakiae8fc532013-04-22 11:17:35 +090051from tempest.services.compute.xml.aggregates_client import AggregatesClientXML
Leo Toyodaa5278912013-04-16 15:40:12 +090052from tempest.services.compute.xml.availability_zone_client import \
53 AvailabilityZoneClientXML
dwallecke62b9f02012-10-10 23:34:42 -050054from tempest.services.compute.xml.extensions_client import ExtensionsClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040055from tempest.services.compute.xml.fixed_ips_client import FixedIPsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050056from tempest.services.compute.xml.flavors_client import FlavorsClientXML
57from tempest.services.compute.xml.floating_ips_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053058 FloatingIPsClientXML
Tony Yang3d5f1632013-06-06 14:17:57 +080059from tempest.services.compute.xml.hypervisor_client import HypervisorClientXML
dwallecke62b9f02012-10-10 23:34:42 -050060from tempest.services.compute.xml.images_client import ImagesClientXML
ivan-zhuef7a1bd2013-10-22 17:56:46 +080061from tempest.services.compute.xml.instance_usage_audit_log_client import \
62 InstanceUsagesAuditLogClientXML
Sean Dague2416cf32013-04-10 08:29:07 -040063from tempest.services.compute.xml.interfaces_client import \
64 InterfacesClientXML
dwallecke62b9f02012-10-10 23:34:42 -050065from tempest.services.compute.xml.keypairs_client import KeyPairsClientXML
66from tempest.services.compute.xml.limits_client import LimitsClientXML
rajalakshmi-ganesan1982c3c2013-01-10 14:56:45 +053067from tempest.services.compute.xml.quotas_client import QuotasClientXML
dwallecke62b9f02012-10-10 23:34:42 -050068from tempest.services.compute.xml.security_groups_client \
harika-vakadi1a9ad612012-12-14 19:12:08 +053069 import SecurityGroupsClientXML
dwallecke62b9f02012-10-10 23:34:42 -050070from tempest.services.compute.xml.servers_client import ServersClientXML
Leo Toyoda3ae31e12013-04-19 11:19:57 +090071from tempest.services.compute.xml.services_client import ServicesClientXML
Leo Toyodad80b6a02013-05-08 12:15:13 +090072from tempest.services.compute.xml.tenant_usages_client import \
73 TenantUsagesClientXML
Matthew Treinisha83a16e2012-12-07 13:44:02 -050074from tempest.services.compute.xml.volumes_extensions_client import \
harika-vakadi1a9ad612012-12-14 19:12:08 +053075 VolumesExtensionsClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010076from tempest.services.identity.json.identity_client import IdentityClientJSON
77from tempest.services.identity.json.identity_client import TokenClientJSON
nayna-patel914b4712013-07-16 08:29:05 +000078from tempest.services.identity.v3.json.credentials_client import \
79 CredentialsClientJSON
Sean Dague2416cf32013-04-10 08:29:07 -040080from tempest.services.identity.v3.json.endpoints_client import \
81 EndPointClientJSON
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053082from tempest.services.identity.v3.json.identity_client import \
83 IdentityV3ClientJSON
nayna-patelb35f7232013-06-28 07:08:44 +000084from tempest.services.identity.v3.json.identity_client import V3TokenClientJSON
harika-vakadi40e10112013-02-08 14:38:09 +053085from tempest.services.identity.v3.json.policy_client import PolicyClientJSON
harika-vakadia92dd742013-02-19 20:41:22 +053086from tempest.services.identity.v3.json.service_client import \
87 ServiceClientJSON
nayna-patel914b4712013-07-16 08:29:05 +000088from tempest.services.identity.v3.xml.credentials_client import \
89 CredentialsClientXML
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053090from tempest.services.identity.v3.xml.endpoints_client import EndPointClientXML
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053091from tempest.services.identity.v3.xml.identity_client import \
92 IdentityV3ClientXML
nayna-patelb35f7232013-06-28 07:08:44 +000093from tempest.services.identity.v3.xml.identity_client import V3TokenClientXML
harika-vakadi40e10112013-02-08 14:38:09 +053094from tempest.services.identity.v3.xml.policy_client import PolicyClientXML
harika-vakadia92dd742013-02-19 20:41:22 +053095from tempest.services.identity.v3.xml.service_client import \
96 ServiceClientXML
Attila Fazekas407b6db2013-01-19 12:48:36 +010097from tempest.services.identity.xml.identity_client import IdentityClientXML
98from tempest.services.identity.xml.identity_client import TokenClientXML
Matthew Treinish6d59c992013-03-01 16:20:04 -050099from tempest.services.image.v1.json.image_client import ImageClientJSON
Matthew Treinisha62347f2013-03-01 16:37:30 -0500100from tempest.services.image.v2.json.image_client import ImageClientV2JSON
raiesmh0867698322013-08-20 13:09:01 +0530101from tempest.services.network.json.network_client import NetworkClientJSON
102from tempest.services.network.xml.network_client import NetworkClientXML
dwalleck5d734432012-10-04 01:11:47 -0500103from tempest.services.object_storage.account_client import AccountClient
harika-vakadi2daed0a2013-01-01 20:51:39 +0530104from tempest.services.object_storage.account_client import \
105 AccountClientCustomizedHeader
Attila Fazekas6968dd52013-02-15 17:05:53 +0100106from tempest.services.object_storage.container_client import ContainerClient
107from tempest.services.object_storage.object_client import ObjectClient
108from tempest.services.object_storage.object_client import \
109 ObjectClientCustomizedHeader
Steve Bakerc60e4e32013-05-06 15:22:41 +1200110from tempest.services.orchestration.json.orchestration_client import \
111 OrchestrationClient
Attila Fazekas6968dd52013-02-15 17:05:53 +0100112from tempest.services.volume.json.admin.volume_types_client import \
113 VolumeTypesClientJSON
114from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
115from tempest.services.volume.json.volumes_client import VolumesClientJSON
116from tempest.services.volume.xml.admin.volume_types_client import \
117 VolumeTypesClientXML
118from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
119from tempest.services.volume.xml.volumes_client import VolumesClientXML
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800120
Jay Pipes3f981df2012-03-27 18:59:44 -0400121LOG = logging.getLogger(__name__)
122
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800123
Daryl Walleck1465d612011-11-02 02:22:15 -0500124class Manager(object):
125
Jay Pipes3f981df2012-03-27 18:59:44 -0400126 """
127 Top level manager for OpenStack Compute clients
128 """
129
James E. Blaire6d8ee12013-01-18 21:33:45 +0000130 def __init__(self, username=None, password=None, tenant_name=None,
131 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400132 """
133 We allow overriding of the credentials used within the various
134 client classes managed by the Manager object. Left as None, the
135 standard username/password/tenant_name is used.
136
137 :param username: Override of the username
138 :param password: Override of the password
139 :param tenant_name: Override of the tenant name
140 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400141 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800142
Jay Pipesf38eaac2012-06-21 13:37:35 -0400143 # If no creds are provided, we fall back on the defaults
144 # in the config file for the Compute API.
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100145 self.username = username or self.config.identity.username
146 self.password = password or self.config.identity.password
147 self.tenant_name = tenant_name or self.config.identity.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500148
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700149 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400150 msg = ("Missing required credentials. "
Sean Dague43cd9052013-07-19 12:20:04 -0400151 "username: %(u)s, password: %(p)s, "
152 "tenant_name: %(t)s" %
153 {'u': username, 'p': password, 't': tenant_name})
Jay Pipes3f981df2012-03-27 18:59:44 -0400154 raise exceptions.InvalidConfiguration(msg)
155
Jay Pipes7c88eb22013-01-16 21:32:43 -0500156 self.auth_url = self.config.identity.uri
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500157 self.auth_url_v3 = self.config.identity.uri_v3
Daryl Walleck587385b2012-03-03 13:00:26 -0600158
Li Ma216550f2013-06-12 11:26:08 -0700159 client_args = (self.config, self.username, self.password,
160 self.auth_url, self.tenant_name)
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500161
Li Ma216550f2013-06-12 11:26:08 -0700162 if self.auth_url_v3:
163 auth_version = 'v3'
164 client_args_v3_auth = (self.config, self.username,
165 self.password, self.auth_url_v3,
166 self.tenant_name, auth_version)
Daryl Walleck1465d612011-11-02 02:22:15 -0500167 else:
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500168 client_args_v3_auth = None
169
Attila Fazekas7e678de2013-07-13 14:13:28 +0200170 self.servers_client_v3_auth = None
171
172 if interface == 'xml':
173 self.servers_client = ServersClientXML(*client_args)
174 self.limits_client = LimitsClientXML(*client_args)
175 self.images_client = ImagesClientXML(*client_args)
176 self.keypairs_client = KeyPairsClientXML(*client_args)
177 self.quotas_client = QuotasClientXML(*client_args)
178 self.flavors_client = FlavorsClientXML(*client_args)
179 self.extensions_client = ExtensionsClientXML(*client_args)
180 self.volumes_extensions_client = VolumesExtensionsClientXML(
181 *client_args)
182 self.floating_ips_client = FloatingIPsClientXML(*client_args)
183 self.snapshots_client = SnapshotsClientXML(*client_args)
184 self.volumes_client = VolumesClientXML(*client_args)
185 self.volume_types_client = VolumeTypesClientXML(*client_args)
186 self.identity_client = IdentityClientXML(*client_args)
187 self.identity_v3_client = IdentityV3ClientXML(*client_args)
188 self.token_client = TokenClientXML(self.config)
189 self.security_groups_client = SecurityGroupsClientXML(
190 *client_args)
191 self.interfaces_client = InterfacesClientXML(*client_args)
192 self.endpoints_client = EndPointClientXML(*client_args)
193 self.fixed_ips_client = FixedIPsClientXML(*client_args)
194 self.availability_zone_client = AvailabilityZoneClientXML(
195 *client_args)
196 self.service_client = ServiceClientXML(*client_args)
197 self.aggregates_client = AggregatesClientXML(*client_args)
198 self.services_client = ServicesClientXML(*client_args)
199 self.tenant_usages_client = TenantUsagesClientXML(*client_args)
200 self.policy_client = PolicyClientXML(*client_args)
201 self.hypervisor_client = HypervisorClientXML(*client_args)
202 self.token_v3_client = V3TokenClientXML(*client_args)
203 self.network_client = NetworkClientXML(*client_args)
204 self.credentials_client = CredentialsClientXML(*client_args)
ivan-zhuef7a1bd2013-10-22 17:56:46 +0800205 self.instance_usages_audit_log_client = \
206 InstanceUsagesAuditLogClientXML(*client_args)
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500207
208 if client_args_v3_auth:
Attila Fazekas7e678de2013-07-13 14:13:28 +0200209 self.servers_client_v3_auth = ServersClientXML(
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500210 *client_args_v3_auth)
Brant Knudsonc7ca3342013-03-28 21:08:50 -0500211
Attila Fazekas7e678de2013-07-13 14:13:28 +0200212 elif interface == 'json':
213 self.servers_client = ServersClientJSON(*client_args)
214 self.limits_client = LimitsClientJSON(*client_args)
215 self.images_client = ImagesClientJSON(*client_args)
216 self.keypairs_client = KeyPairsClientJSON(*client_args)
217 self.quotas_client = QuotasClientJSON(*client_args)
218 self.flavors_client = FlavorsClientJSON(*client_args)
219 self.extensions_client = ExtensionsClientJSON(*client_args)
220 self.volumes_extensions_client = VolumesExtensionsClientJSON(
221 *client_args)
222 self.floating_ips_client = FloatingIPsClientJSON(*client_args)
223 self.snapshots_client = SnapshotsClientJSON(*client_args)
224 self.volumes_client = VolumesClientJSON(*client_args)
225 self.volume_types_client = VolumeTypesClientJSON(*client_args)
226 self.identity_client = IdentityClientJSON(*client_args)
227 self.identity_v3_client = IdentityV3ClientJSON(*client_args)
228 self.token_client = TokenClientJSON(self.config)
229 self.security_groups_client = SecurityGroupsClientJSON(
230 *client_args)
231 self.interfaces_client = InterfacesClientJSON(*client_args)
232 self.endpoints_client = EndPointClientJSON(*client_args)
233 self.fixed_ips_client = FixedIPsClientJSON(*client_args)
234 self.availability_zone_client = AvailabilityZoneClientJSON(
235 *client_args)
236 self.service_client = ServiceClientJSON(*client_args)
237 self.aggregates_client = AggregatesClientJSON(*client_args)
238 self.services_client = ServicesClientJSON(*client_args)
239 self.tenant_usages_client = TenantUsagesClientJSON(*client_args)
240 self.policy_client = PolicyClientJSON(*client_args)
241 self.hypervisor_client = HypervisorClientJSON(*client_args)
242 self.token_v3_client = V3TokenClientJSON(*client_args)
243 self.network_client = NetworkClientJSON(*client_args)
244 self.credentials_client = CredentialsClientJSON(*client_args)
ivan-zhuef7a1bd2013-10-22 17:56:46 +0800245 self.instance_usages_audit_log_client = \
246 InstanceUsagesAuditLogClientJSON(*client_args)
Attila Fazekas7e678de2013-07-13 14:13:28 +0200247
248 if client_args_v3_auth:
249 self.servers_client_v3_auth = ServersClientJSON(
250 *client_args_v3_auth)
251 else:
Dan Smithcf8fab62012-08-14 08:03:48 -0700252 msg = "Unsupported interface type `%s'" % interface
253 raise exceptions.InvalidConfiguration(msg)
Attila Fazekas7e678de2013-07-13 14:13:28 +0200254
255 # common clients
Attila Fazekas8e99b992013-02-24 09:53:23 +0100256 self.hosts_client = HostsClientJSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500257 self.account_client = AccountClient(*client_args)
Frederic Lepiedcf1868b2013-07-28 18:07:15 -0400258 if self.config.service_available.glance:
259 self.image_client = ImageClientJSON(*client_args)
260 self.image_client_v2 = ImageClientV2JSON(*client_args)
dwalleck5d734432012-10-04 01:11:47 -0500261 self.container_client = ContainerClient(*client_args)
262 self.object_client = ObjectClient(*client_args)
Steve Bakerc60e4e32013-05-06 15:22:41 +1200263 self.orchestration_client = OrchestrationClient(*client_args)
Attila Fazekas1aed6202013-02-11 14:47:45 +0100264 self.ec2api_client = botoclients.APIClientEC2(*client_args)
265 self.s3_client = botoclients.ObjectClientS3(*client_args)
harika-vakadi1a9ad612012-12-14 19:12:08 +0530266 self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
harika-vakadi2daed0a2013-01-01 20:51:39 +0530267 self.custom_account_client = \
268 AccountClientCustomizedHeader(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500269
270
Jay Pipesff10d552012-04-06 14:18:50 -0400271class AltManager(Manager):
272
273 """
274 Manager object that uses the alt_XXX credentials for its
275 managed client objects
276 """
277
278 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400279 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100280 super(AltManager, self).__init__(conf.identity.alt_username,
281 conf.identity.alt_password,
282 conf.identity.alt_tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400283
284
285class AdminManager(Manager):
286
287 """
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100288 Manager object that uses the admin credentials for its
Jay Pipesff10d552012-04-06 14:18:50 -0400289 managed client objects
290 """
291
James E. Blaire6d8ee12013-01-18 21:33:45 +0000292 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400293 conf = config.TempestConfig()
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100294 super(AdminManager, self).__init__(conf.identity.admin_username,
295 conf.identity.admin_password,
296 conf.identity.admin_tenant_name,
James E. Blaire6d8ee12013-01-18 21:33:45 +0000297 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400298
299
Attila Fazekascadcb1f2013-01-21 23:10:53 +0100300class ComputeAdminManager(Manager):
301
302 """
303 Manager object that uses the compute_admin credentials for its
304 managed client objects
305 """
306
307 def __init__(self, interface='json'):
308 conf = config.TempestConfig()
309 base = super(ComputeAdminManager, self)
310 base.__init__(conf.compute_admin.username,
311 conf.compute_admin.password,
312 conf.compute_admin.tenant_name,
313 interface=interface)
Steve Bakerc60e4e32013-05-06 15:22:41 +1200314
315
316class OrchestrationManager(Manager):
317 """
318 Manager object that uses the admin credentials for its
319 so that heat templates can create users
320 """
321 def __init__(self, interface='json'):
322 conf = config.TempestConfig()
323 base = super(OrchestrationManager, self)
324 base.__init__(conf.identity.admin_username,
325 conf.identity.admin_password,
Steve Bakerfd86f3c2013-06-28 12:51:20 +1200326 conf.identity.tenant_name,
Steve Bakerc60e4e32013-05-06 15:22:41 +1200327 interface=interface)