blob: 945ce3a859472acd776c6383dd1b0fa515782673 [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 Melloeda03b52012-08-22 23:47:29 -030024from tempest.services.nova.json.flavors_client import FlavorsClientJSON
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070025from tempest.services.volume.json.volumes_client import VolumesClient
Daryl Wallecked8bef32011-12-05 23:02:08 -060026from tempest.services.nova.json.images_client import ImagesClient
Matthew Treinish33634462012-08-16 16:51:23 -040027from tempest.services.nova.json.limits_client import LimitsClientJSON
Dan Smithcf8fab62012-08-14 08:03:48 -070028from tempest.services.nova.json.servers_client import ServersClientJSON
donald-ngo20b6bca2011-12-15 13:35:12 -080029from tempest.services.nova.json.extensions_client import ExtensionsClient
Ravikumar Venkatesanaf7ab1c2012-01-17 12:54:22 -080030from tempest.services.nova.json.security_groups_client \
31import SecurityGroupsClient
sapan-konaed37d732012-01-18 22:52:12 +053032from tempest.services.nova.json.floating_ips_client import FloatingIPsClient
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 \
35import VolumesExtensionsClient
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +053036from tempest.services.nova.json.console_output_client \
37import ConsoleOutputsClient
Tiago Melloeda03b52012-08-22 23:47:29 -030038from tempest.services.nova.xml.flavors_client import FlavorsClientXML
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040039from tempest.services.nova.xml.keypairs_client import KeyPairsClientXML
Matthew Treinish33634462012-08-16 16:51:23 -040040from tempest.services.nova.xml.limits_client import LimitsClientXML
Dan Smithcf8fab62012-08-14 08:03:48 -070041from tempest.services.nova.xml.servers_client import ServersClientXML
Daryl Walleck1465d612011-11-02 02:22:15 -050042
Jay Pipes3f981df2012-03-27 18:59:44 -040043LOG = logging.getLogger(__name__)
44
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040045KEYPAIRS_CLIENTS = {
46 "json": KeyPairsClientJSON,
47 "xml": KeyPairsClientXML,
48}
49
Dan Smithcf8fab62012-08-14 08:03:48 -070050SERVERS_CLIENTS = {
51 "json": ServersClientJSON,
52 "xml": ServersClientXML,
53}
54
Matthew Treinish33634462012-08-16 16:51:23 -040055LIMITS_CLIENTS = {
56 "json": LimitsClientJSON,
57 "xml": LimitsClientXML,
58}
59
Tiago Melloeda03b52012-08-22 23:47:29 -030060FLAVORS_CLIENTS = {
61 "json": FlavorsClientJSON,
62 "xml": FlavorsClientXML
63}
64
Daryl Walleck1465d612011-11-02 02:22:15 -050065
66class Manager(object):
67
Jay Pipes3f981df2012-03-27 18:59:44 -040068 """
69 Top level manager for OpenStack Compute clients
70 """
71
Dan Smithcf8fab62012-08-14 08:03:48 -070072 def __init__(self, username=None, password=None, tenant_name=None,
73 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -040074 """
75 We allow overriding of the credentials used within the various
76 client classes managed by the Manager object. Left as None, the
77 standard username/password/tenant_name is used.
78
79 :param username: Override of the username
80 :param password: Override of the password
81 :param tenant_name: Override of the tenant name
82 """
Jay Pipesf38eaac2012-06-21 13:37:35 -040083 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -080084
Jay Pipesf38eaac2012-06-21 13:37:35 -040085 # If no creds are provided, we fall back on the defaults
86 # in the config file for the Compute API.
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070087 self.username = username or self.config.compute.username
88 self.password = password or self.config.compute.password
89 self.tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -050090
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070091 if None in (self.username, self.password, self.tenant_name):
Jay Pipes3f981df2012-03-27 18:59:44 -040092 msg = ("Missing required credentials. "
93 "username: %(username)s, password: %(password)s, "
94 "tenant_name: %(tenant_name)s") % locals()
95 raise exceptions.InvalidConfiguration(msg)
96
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070097 self.auth_url = self.config.identity.auth_url
Daryl Walleck587385b2012-03-03 13:00:26 -060098
99 if self.config.identity.strategy == 'keystone':
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700100 client_args = (self.config, self.username, self.password,
101 self.auth_url, self.tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500102 else:
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700103 client_args = (self.config, self.username, self.password,
104 self.auth_url)
Daryl Walleck587385b2012-03-03 13:00:26 -0600105
Dan Smithcf8fab62012-08-14 08:03:48 -0700106 try:
107 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400108 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400109 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300110 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700111 except KeyError:
112 msg = "Unsupported interface type `%s'" % interface
113 raise exceptions.InvalidConfiguration(msg)
Daryl Walleck587385b2012-03-03 13:00:26 -0600114 self.images_client = ImagesClient(*client_args)
Daryl Walleck587385b2012-03-03 13:00:26 -0600115 self.extensions_client = ExtensionsClient(*client_args)
Daryl Walleck587385b2012-03-03 13:00:26 -0600116 self.security_groups_client = SecurityGroupsClient(*client_args)
117 self.floating_ips_client = FloatingIPsClient(*client_args)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530118 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530119 self.network_client = NetworkClient(*client_args)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700120 self.volumes_extensions_client = VolumesExtensionsClient(*client_args)
121 self.volumes_client = VolumesClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500122
123
Jay Pipesff10d552012-04-06 14:18:50 -0400124class AltManager(Manager):
125
126 """
127 Manager object that uses the alt_XXX credentials for its
128 managed client objects
129 """
130
131 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400132 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400133 super(AltManager, self).__init__(conf.compute.alt_username,
134 conf.compute.alt_password,
135 conf.compute.alt_tenant_name)
136
137
138class AdminManager(Manager):
139
140 """
141 Manager object that uses the alt_XXX credentials for its
142 managed client objects
143 """
144
Tiago Melloeda03b52012-08-22 23:47:29 -0300145 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400146 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400147 super(AdminManager, self).__init__(conf.compute_admin.username,
148 conf.compute_admin.password,
Tiago Melloeda03b52012-08-22 23:47:29 -0300149 conf.compute_admin.tenant_name,
150 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400151
152
Jay Pipes50677282012-01-06 15:39:20 -0500153class ServiceManager(object):
154
155 """
156 Top-level object housing clients for OpenStack APIs
157 """
158
159 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400160 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500161 self.services = {}
162 self.services['image'] = image_service.Service(self.config)
163 self.images = self.services['image']