blob: 89b77184efc3f2c08814ffa2dc304282a54228c7 [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
Matthew Treinish9854d5b2012-09-20 10:22:13 -040048from tempest.services.volume.json.volumes_client import VolumesClientJSON
49from tempest.services.volume.xml.volumes_client import VolumesClientXML
Daryl Walleck1465d612011-11-02 02:22:15 -050050
Jay Pipes3f981df2012-03-27 18:59:44 -040051LOG = logging.getLogger(__name__)
52
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -040053IMAGES_CLIENTS = {
54 "json": ImagesClientJSON,
55 "xml": ImagesClientXML,
56}
57
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040058KEYPAIRS_CLIENTS = {
59 "json": KeyPairsClientJSON,
60 "xml": KeyPairsClientXML,
61}
62
Dan Smithcf8fab62012-08-14 08:03:48 -070063SERVERS_CLIENTS = {
64 "json": ServersClientJSON,
65 "xml": ServersClientXML,
66}
67
Matthew Treinish33634462012-08-16 16:51:23 -040068LIMITS_CLIENTS = {
69 "json": LimitsClientJSON,
70 "xml": LimitsClientXML,
71}
72
Tiago Melloeda03b52012-08-22 23:47:29 -030073FLAVORS_CLIENTS = {
74 "json": FlavorsClientJSON,
75 "xml": FlavorsClientXML
76}
77
Tiago Mello89126c32012-08-27 11:14:03 -030078EXTENSIONS_CLIENTS = {
79 "json": ExtensionsClientJSON,
80 "xml": ExtensionsClientXML
81}
82
Matthew Treinish4e086902012-08-17 17:52:22 -040083VOLUMES_EXTENSIONS_CLIENTS = {
84 "json": VolumesExtensionsClientJSON,
85 "xml": VolumesExtensionsClientXML,
86}
87
Vincent Hou22f03c72012-08-24 17:55:13 +080088FLOAT_CLIENTS = {
89 "json": FloatingIPsClientJSON,
90 "xml": FloatingIPsClientXML,
91}
92
Matthew Treinish9854d5b2012-09-20 10:22:13 -040093VOLUMES_CLIENTS = {
94 "json": VolumesClientJSON,
95 "xml": VolumesClientXML,
96}
97
Daryl Walleck1465d612011-11-02 02:22:15 -050098
99class Manager(object):
100
Jay Pipes3f981df2012-03-27 18:59:44 -0400101 """
102 Top level manager for OpenStack Compute clients
103 """
104
Dan Smithcf8fab62012-08-14 08:03:48 -0700105 def __init__(self, username=None, password=None, tenant_name=None,
106 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -0400107 """
108 We allow overriding of the credentials used within the various
109 client classes managed by the Manager object. Left as None, the
110 standard username/password/tenant_name is used.
111
112 :param username: Override of the username
113 :param password: Override of the password
114 :param tenant_name: Override of the tenant name
115 """
Jay Pipesf38eaac2012-06-21 13:37:35 -0400116 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -0800117
Jay Pipesf38eaac2012-06-21 13:37:35 -0400118 # If no creds are provided, we fall back on the defaults
119 # in the config file for the Compute API.
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700120 self.username = username or self.config.compute.username
121 self.password = password or self.config.compute.password
122 self.tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -0500123
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700124 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -0400125 msg = ("Missing required credentials. "
126 "username: %(username)s, password: %(password)s, "
127 "tenant_name: %(tenant_name)s") % locals()
128 raise exceptions.InvalidConfiguration(msg)
129
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700130 self.auth_url = self.config.identity.auth_url
Daryl Walleck587385b2012-03-03 13:00:26 -0600131
132 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700133 client_args = (self.config, self.username, self.password,
134 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500135 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700136 client_args = (self.config, self.username, self.password,
137 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600138
Dan Smithcf8fab62012-08-14 08:03:48 -0700139 try:
140 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400141 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodrigues6e373242012-08-27 18:59:19 -0400142 self.images_client = IMAGES_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400143 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300144 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Tiago Mello89126c32012-08-27 11:14:03 -0300145 self.extensions_client = \
146 EXTENSIONS_CLIENTS[interface](*client_args)
Matthew Treinish4e086902012-08-17 17:52:22 -0400147 self.volumes_extensions_client = \
148 VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args)
Vincent Hou22f03c72012-08-24 17:55:13 +0800149 self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400150 self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700151 except KeyError:
152 msg = "Unsupported interface type `%s'" % interface
153 raise exceptions.InvalidConfiguration(msg)
Daryl Walleck587385b2012-03-03 13:00:26 -0600154 self.security_groups_client = SecurityGroupsClient(*client_args)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530155 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530156 self.network_client = NetworkClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500157
158
Jay Pipesff10d552012-04-06 14:18:50 -0400159class AltManager(Manager):
160
161 """
162 Manager object that uses the alt_XXX credentials for its
163 managed client objects
164 """
165
166 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400167 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400168 super(AltManager, self).__init__(conf.compute.alt_username,
169 conf.compute.alt_password,
170 conf.compute.alt_tenant_name)
171
172
173class AdminManager(Manager):
174
175 """
176 Manager object that uses the alt_XXX credentials for its
177 managed client objects
178 """
179
Tiago Melloeda03b52012-08-22 23:47:29 -0300180 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400181 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400182 super(AdminManager, self).__init__(conf.compute_admin.username,
183 conf.compute_admin.password,
Tiago Melloeda03b52012-08-22 23:47:29 -0300184 conf.compute_admin.tenant_name,
185 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400186
187
Jay Pipes50677282012-01-06 15:39:20 -0500188class ServiceManager(object):
189
190 """
191 Top-level object housing clients for OpenStack APIs
192 """
193
194 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400195 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500196 self.services = {}
197 self.services['image'] = image_service.Service(self.config)
198 self.images = self.services['image']