blob: 241d8bda74ed94529bb0422fa116bb74298ecee4 [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
Daryl Wallecked8bef32011-12-05 23:02:08 -060025from tempest.services.nova.json.images_client import ImagesClient
Matthew Treinish33634462012-08-16 16:51:23 -040026from tempest.services.nova.json.limits_client import LimitsClientJSON
Dan Smithcf8fab62012-08-14 08:03:48 -070027from tempest.services.nova.json.servers_client import ServersClientJSON
donald-ngo20b6bca2011-12-15 13:35:12 -080028from tempest.services.nova.json.extensions_client import ExtensionsClient
Ravikumar Venkatesanaf7ab1c2012-01-17 12:54:22 -080029from tempest.services.nova.json.security_groups_client \
30import SecurityGroupsClient
sapan-konaed37d732012-01-18 22:52:12 +053031from tempest.services.nova.json.floating_ips_client import FloatingIPsClient
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040032from tempest.services.nova.json.keypairs_client import KeyPairsClientJSON
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053033from tempest.services.nova.json.volumes_client import VolumesClient
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +053034from tempest.services.nova.json.console_output_client \
35import ConsoleOutputsClient
Tiago Melloeda03b52012-08-22 23:47:29 -030036from tempest.services.nova.xml.flavors_client import FlavorsClientXML
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040037from tempest.services.nova.xml.keypairs_client import KeyPairsClientXML
Matthew Treinish33634462012-08-16 16:51:23 -040038from tempest.services.nova.xml.limits_client import LimitsClientXML
Dan Smithcf8fab62012-08-14 08:03:48 -070039from tempest.services.nova.xml.servers_client import ServersClientXML
Daryl Walleck1465d612011-11-02 02:22:15 -050040
Jay Pipes3f981df2012-03-27 18:59:44 -040041LOG = logging.getLogger(__name__)
42
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -040043KEYPAIRS_CLIENTS = {
44 "json": KeyPairsClientJSON,
45 "xml": KeyPairsClientXML,
46}
47
Dan Smithcf8fab62012-08-14 08:03:48 -070048SERVERS_CLIENTS = {
49 "json": ServersClientJSON,
50 "xml": ServersClientXML,
51}
52
Matthew Treinish33634462012-08-16 16:51:23 -040053LIMITS_CLIENTS = {
54 "json": LimitsClientJSON,
55 "xml": LimitsClientXML,
56}
57
Tiago Melloeda03b52012-08-22 23:47:29 -030058FLAVORS_CLIENTS = {
59 "json": FlavorsClientJSON,
60 "xml": FlavorsClientXML
61}
62
Daryl Walleck1465d612011-11-02 02:22:15 -050063
64class Manager(object):
65
Jay Pipes3f981df2012-03-27 18:59:44 -040066 """
67 Top level manager for OpenStack Compute clients
68 """
69
Dan Smithcf8fab62012-08-14 08:03:48 -070070 def __init__(self, username=None, password=None, tenant_name=None,
71 interface='json'):
Jay Pipesff10d552012-04-06 14:18:50 -040072 """
73 We allow overriding of the credentials used within the various
74 client classes managed by the Manager object. Left as None, the
75 standard username/password/tenant_name is used.
76
77 :param username: Override of the username
78 :param password: Override of the password
79 :param tenant_name: Override of the tenant name
80 """
Jay Pipesf38eaac2012-06-21 13:37:35 -040081 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -080082
Jay Pipesf38eaac2012-06-21 13:37:35 -040083 # If no creds are provided, we fall back on the defaults
84 # in the config file for the Compute API.
Jay Pipesff10d552012-04-06 14:18:50 -040085 username = username or self.config.compute.username
86 password = password or self.config.compute.password
87 tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -050088
Jay Pipes3f981df2012-03-27 18:59:44 -040089 if None in (username, password, tenant_name):
90 msg = ("Missing required credentials. "
91 "username: %(username)s, password: %(password)s, "
92 "tenant_name: %(tenant_name)s") % locals()
93 raise exceptions.InvalidConfiguration(msg)
94
Daryl Walleck587385b2012-03-03 13:00:26 -060095 auth_url = self.config.identity.auth_url
96
97 if self.config.identity.strategy == 'keystone':
98 client_args = (self.config, username, password, auth_url,
99 tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -0500100 else:
Daryl Walleck587385b2012-03-03 13:00:26 -0600101 client_args = (self.config, username, password, auth_url)
102
Dan Smithcf8fab62012-08-14 08:03:48 -0700103 try:
104 self.servers_client = SERVERS_CLIENTS[interface](*client_args)
Matthew Treinish33634462012-08-16 16:51:23 -0400105 self.limits_client = LIMITS_CLIENTS[interface](*client_args)
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400106 self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args)
Tiago Melloeda03b52012-08-22 23:47:29 -0300107 self.flavors_client = FLAVORS_CLIENTS[interface](*client_args)
Dan Smithcf8fab62012-08-14 08:03:48 -0700108 except KeyError:
109 msg = "Unsupported interface type `%s'" % interface
110 raise exceptions.InvalidConfiguration(msg)
Daryl Walleck587385b2012-03-03 13:00:26 -0600111 self.images_client = ImagesClient(*client_args)
Daryl Walleck587385b2012-03-03 13:00:26 -0600112 self.extensions_client = ExtensionsClient(*client_args)
Daryl Walleck587385b2012-03-03 13:00:26 -0600113 self.security_groups_client = SecurityGroupsClient(*client_args)
114 self.floating_ips_client = FloatingIPsClient(*client_args)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +0530115 self.volumes_client = VolumesClient(*client_args)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530116 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530117 self.network_client = NetworkClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -0500118
119
Jay Pipesff10d552012-04-06 14:18:50 -0400120class AltManager(Manager):
121
122 """
123 Manager object that uses the alt_XXX credentials for its
124 managed client objects
125 """
126
127 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400128 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400129 super(AltManager, self).__init__(conf.compute.alt_username,
130 conf.compute.alt_password,
131 conf.compute.alt_tenant_name)
132
133
134class AdminManager(Manager):
135
136 """
137 Manager object that uses the alt_XXX credentials for its
138 managed client objects
139 """
140
Tiago Melloeda03b52012-08-22 23:47:29 -0300141 def __init__(self, interface='json'):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400142 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400143 super(AdminManager, self).__init__(conf.compute_admin.username,
144 conf.compute_admin.password,
Tiago Melloeda03b52012-08-22 23:47:29 -0300145 conf.compute_admin.tenant_name,
146 interface=interface)
Jay Pipesff10d552012-04-06 14:18:50 -0400147
148
Jay Pipes50677282012-01-06 15:39:20 -0500149class ServiceManager(object):
150
151 """
152 Top-level object housing clients for OpenStack APIs
153 """
154
155 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400156 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500157 self.services = {}
158 self.services['image'] = image_service.Service(self.config)
159 self.images = self.services['image']