blob: ec0c257a77ffbf0695db64c5f30adbe04cb1d5e4 [file] [log] [blame]
Jay Pipes3f981df2012-03-27 18:59:44 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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
18import logging
19
Jay Pipesf38eaac2012-06-21 13:37:35 -040020from tempest import config
Daryl Walleck587385b2012-03-03 13:00:26 -060021from tempest import exceptions
Jay Pipes50677282012-01-06 15:39:20 -050022from tempest.services.image import service as image_service
Unmesh Gurjar44986832012-05-08 19:57:10 +053023from tempest.services.network.json.network_client import NetworkClient
Tiago Mello89126c32012-08-27 11:14:03 -030024from tempest.services.nova.json.extensions_client import ExtensionsClientJSON
Tiago Melloeda03b52012-08-22 23:47:29 -030025from tempest.services.nova.json.flavors_client import FlavorsClientJSON
Vincent Hou22f03c72012-08-24 17:55:13 +080026from tempest.services.nova.json.floating_ips_client import \
27FloatingIPsClientJSON
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040028from tempest.services.nova.json.images_client import ImagesClientJSON
Matthew Treinish33634462012-08-16 16:51:23 -040029from tempest.services.nova.json.limits_client import LimitsClientJSON
Dan Smithcf8fab62012-08-14 08:03:48 -070030from tempest.services.nova.json.servers_client import ServersClientJSON
Ravikumar Venkatesanaf7ab1c2012-01-17 12:54:22 -080031from tempest.services.nova.json.security_groups_client \
32import SecurityGroupsClient
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040033from tempest.services.nova.json.keypairs_client import KeyPairsClientJSON
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070034from tempest.services.nova.json.volumes_extensions_client \
Matthew Treinish4e086902012-08-17 17:52:22 -040035import VolumesExtensionsClientJSON
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +053036from tempest.services.nova.json.console_output_client \
37import ConsoleOutputsClient
Tiago Mello89126c32012-08-27 11:14:03 -030038from tempest.services.nova.xml.extensions_client import ExtensionsClientXML
Tiago Melloeda03b52012-08-22 23:47:29 -030039from tempest.services.nova.xml.flavors_client import FlavorsClientXML
Vincent Hou22f03c72012-08-24 17:55:13 +080040from tempest.services.nova.xml.floating_ips_client import \
41FloatingIPsClientXML
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040042from tempest.services.nova.xml.images_client import ImagesClientXML
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040043from tempest.services.nova.xml.keypairs_client import KeyPairsClientXML
Matthew Treinish33634462012-08-16 16:51:23 -040044from tempest.services.nova.xml.limits_client import LimitsClientXML
Dan Smithcf8fab62012-08-14 08:03:48 -070045from tempest.services.nova.xml.servers_client import ServersClientXML
Matthew Treinish4e086902012-08-17 17:52:22 -040046from tempest.services.nova.xml.volumes_extensions_client \
47import VolumesExtensionsClientXML
48from tempest.services.volume.json.volumes_client import VolumesClient
Daryl Walleck1465d612011-11-02 02:22:15 -050049
Jay Pipes3f981df2012-03-27 18:59:44 -040050LOG = logging.getLogger(__name__)
51
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040052IMAGES_CLIENTS = {
53 "json": ImagesClientJSON,
54 "xml": ImagesClientXML,
55}
56
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040057KEYPAIRS_CLIENTS = {
58 "json": KeyPairsClientJSON,
59 "xml": KeyPairsClientXML,
60}
61
Dan Smithcf8fab62012-08-14 08:03:48 -070062SERVERS_CLIENTS = {
63 "json": ServersClientJSON,
64 "xml": ServersClientXML,
65}
66
Matthew Treinish33634462012-08-16 16:51:23 -040067LIMITS_CLIENTS = {
68 "json": LimitsClientJSON,
69 "xml": LimitsClientXML,
70}
71
Tiago Melloeda03b52012-08-22 23:47:29 -030072FLAVORS_CLIENTS = {
73 "json": FlavorsClientJSON,
74 "xml": FlavorsClientXML
75}
76
Tiago Mello89126c32012-08-27 11:14:03 -030077EXTENSIONS_CLIENTS = {
78 "json": ExtensionsClientJSON,
79 "xml": ExtensionsClientXML
80}
81
Matthew Treinish4e086902012-08-17 17:52:22 -040082VOLUMES_EXTENSIONS_CLIENTS = {
83 "json": VolumesExtensionsClientJSON,
84 "xml": VolumesExtensionsClientXML,
85}
86
Vincent Hou22f03c72012-08-24 17:55:13 +080087FLOAT_CLIENTS = {
88 "json": FloatingIPsClientJSON,
89 "xml": FloatingIPsClientXML,
90}
91
Daryl Walleck1465d612011-11-02 02:22:15 -050092
93class Manager(object):
94
Jay Pipes3f981df2012-03-27 18:59:44 -040095 """
96 Top level manager for OpenStack Compute clients
97 """
98
Dan Smithcf8fab62012-08-14 08:03:48 -070099 def __init__(self, username=None, password=None, tenant_name=None,
100 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400101 """
102 We allow overriding of the credentials used within the various
103 client classes managed by the Manager object. Left as None, the
104 standard username/password/tenant_name is used.
105
106 :param username: Override of the username
107 :param password: Override of the password
108 :param tenant_name: Override of the tenant name
109 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400110 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800111
Jay Pipesf38eaac2012-06-21 13:37:35 -0400112 # If no creds are provided, we fall back on the defaults
113 # in the config file for the Compute API.
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700114 self.username = username or self.config.compute.username
115 self.password = password or self.config.compute.password
116 self.tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500117
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700118 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400119 msg = ("Missing required credentials. "
120 "username: %(username)s, password: %(password)s, "
121 "tenant_name: %(tenant_name)s") % locals()
122 raise exceptions.InvalidConfiguration(msg)
123
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700124 self.auth_url = self.config.identity.auth_url
Daryl Walleck587385b2012-03-03 13:00:26 -0600125
126 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700127 client_args = (self.config, self.username, self.password,
128 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500129 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700130 client_args = (self.config, self.username, self.password,
131 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600132
Dan Smithcf8fab62012-08-14 08:03:48 -0700133 try:
134 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400135 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400136 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400137 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300138 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Tiago Mello89126c32012-08-27 11:14:03 -0300139 self.extensions_client = \
140 EXTENSIONS_CLIENTS[interface](*client_args)
Matthew Treinish4e086902012-08-17 17:52:22 -0400141 self.volumes_extensions_client = \
142 VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
Vincent Hou22f03c72012-08-24 17:55:13 +0800143 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700144 except KeyError:
145 msg = "Unsupported interface type `%s'" % interface
146 raise exceptions.InvalidConfiguration(msg)
Daryl Walleck587385b2012-03-03 13:00:26 -0600147 self.security_groups_client = SecurityGroupsClient(*client_args)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530148 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530149 self.network_client = NetworkClient(*client_args)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700150 self.volumes_client = VolumesClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500151
152
Jay Pipesff10d552012-04-06 14:18:50 -0400153class AltManager(Manager):
154
155 """
156 Manager object that uses the alt_XXX credentials for its
157 managed client objects
158 """
159
160 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400161 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400162 super(AltManager, self).__init__(conf.compute.alt_username,
163 conf.compute.alt_password,
164 conf.compute.alt_tenant_name)
165
166
167class AdminManager(Manager):
168
169 """
170 Manager object that uses the alt_XXX credentials for its
171 managed client objects
172 """
173
Tiago Melloeda03b52012-08-22 23:47:29 -0300174 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400175 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400176 super(AdminManager, self).__init__(conf.compute_admin.username,
177 conf.compute_admin.password,
Tiago Melloeda03b52012-08-22 23:47:29 -0300178 conf.compute_admin.tenant_name,
179 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400180
181
Jay Pipes50677282012-01-06 15:39:20 -0500182class ServiceManager(object):
183
184 """
185 Top-level object housing clients for OpenStack APIs
186 """
187
188 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400189 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500190 self.services = {}
191 self.services['image'] = image_service.Service(self.config)
192 self.images = self.services['image']