Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 1 | # 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 | |
| 18 | import logging |
| 19 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 20 | from tempest import config |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 21 | from tempest import exceptions |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 22 | from tempest.services.identity.json.admin_client import AdminClientJSON |
| 23 | from tempest.services.identity.json.admin_client import TokenClientJSON |
| 24 | from tempest.services.identity.xml.admin_client import AdminClientXML |
| 25 | from tempest.services.identity.xml.admin_client import TokenClientXML |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 26 | from tempest.services.image import service as image_service |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 27 | from tempest.services.network.json.network_client import NetworkClient |
Tiago Mello | 89126c3 | 2012-08-27 11:14:03 -0300 | [diff] [blame] | 28 | from tempest.services.nova.json.extensions_client import ExtensionsClientJSON |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 29 | from tempest.services.nova.json.flavors_client import FlavorsClientJSON |
Vincent Hou | 22f03c7 | 2012-08-24 17:55:13 +0800 | [diff] [blame] | 30 | from tempest.services.nova.json.floating_ips_client import \ |
| 31 | FloatingIPsClientJSON |
Mauro S. M. Rodrigues | 6e37324 | 2012-08-27 18:59:19 -0400 | [diff] [blame] | 32 | from tempest.services.nova.json.images_client import ImagesClientJSON |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 33 | from tempest.services.nova.json.limits_client import LimitsClientJSON |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 34 | from tempest.services.nova.json.servers_client import ServersClientJSON |
Ravikumar Venkatesan | af7ab1c | 2012-01-17 12:54:22 -0800 | [diff] [blame] | 35 | from tempest.services.nova.json.security_groups_client \ |
Vincent Hou | ead03dc | 2012-08-24 21:35:11 +0800 | [diff] [blame^] | 36 | import SecurityGroupsClientJSON |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 37 | from tempest.services.nova.json.keypairs_client import KeyPairsClientJSON |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 38 | from tempest.services.nova.json.volumes_extensions_client \ |
Matthew Treinish | 4e08690 | 2012-08-17 17:52:22 -0400 | [diff] [blame] | 39 | import VolumesExtensionsClientJSON |
rajalakshmi-ganesan | 72ea31a | 2012-05-25 11:59:10 +0530 | [diff] [blame] | 40 | from tempest.services.nova.json.console_output_client \ |
| 41 | import ConsoleOutputsClient |
Tiago Mello | 89126c3 | 2012-08-27 11:14:03 -0300 | [diff] [blame] | 42 | from tempest.services.nova.xml.extensions_client import ExtensionsClientXML |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 43 | from tempest.services.nova.xml.flavors_client import FlavorsClientXML |
Vincent Hou | 22f03c7 | 2012-08-24 17:55:13 +0800 | [diff] [blame] | 44 | from tempest.services.nova.xml.floating_ips_client import \ |
| 45 | FloatingIPsClientXML |
Mauro S. M. Rodrigues | 6e37324 | 2012-08-27 18:59:19 -0400 | [diff] [blame] | 46 | from tempest.services.nova.xml.images_client import ImagesClientXML |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 47 | from tempest.services.nova.xml.keypairs_client import KeyPairsClientXML |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 48 | from tempest.services.nova.xml.limits_client import LimitsClientXML |
Vincent Hou | ead03dc | 2012-08-24 21:35:11 +0800 | [diff] [blame^] | 49 | from tempest.services.nova.xml.security_groups_client \ |
| 50 | import SecurityGroupsClientXML |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 51 | from tempest.services.nova.xml.servers_client import ServersClientXML |
Matthew Treinish | 4e08690 | 2012-08-17 17:52:22 -0400 | [diff] [blame] | 52 | from tempest.services.nova.xml.volumes_extensions_client \ |
| 53 | import VolumesExtensionsClientXML |
Matthew Treinish | 9854d5b | 2012-09-20 10:22:13 -0400 | [diff] [blame] | 54 | from tempest.services.volume.json.volumes_client import VolumesClientJSON |
| 55 | from tempest.services.volume.xml.volumes_client import VolumesClientXML |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 56 | |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 57 | |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 58 | LOG = logging.getLogger(__name__) |
| 59 | |
Mauro S. M. Rodrigues | 6e37324 | 2012-08-27 18:59:19 -0400 | [diff] [blame] | 60 | IMAGES_CLIENTS = { |
| 61 | "json": ImagesClientJSON, |
| 62 | "xml": ImagesClientXML, |
| 63 | } |
| 64 | |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 65 | KEYPAIRS_CLIENTS = { |
| 66 | "json": KeyPairsClientJSON, |
| 67 | "xml": KeyPairsClientXML, |
| 68 | } |
| 69 | |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 70 | SERVERS_CLIENTS = { |
| 71 | "json": ServersClientJSON, |
| 72 | "xml": ServersClientXML, |
| 73 | } |
| 74 | |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 75 | LIMITS_CLIENTS = { |
| 76 | "json": LimitsClientJSON, |
| 77 | "xml": LimitsClientXML, |
| 78 | } |
| 79 | |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 80 | FLAVORS_CLIENTS = { |
| 81 | "json": FlavorsClientJSON, |
| 82 | "xml": FlavorsClientXML |
| 83 | } |
| 84 | |
Tiago Mello | 89126c3 | 2012-08-27 11:14:03 -0300 | [diff] [blame] | 85 | EXTENSIONS_CLIENTS = { |
| 86 | "json": ExtensionsClientJSON, |
| 87 | "xml": ExtensionsClientXML |
| 88 | } |
| 89 | |
Matthew Treinish | 4e08690 | 2012-08-17 17:52:22 -0400 | [diff] [blame] | 90 | VOLUMES_EXTENSIONS_CLIENTS = { |
| 91 | "json": VolumesExtensionsClientJSON, |
| 92 | "xml": VolumesExtensionsClientXML, |
| 93 | } |
| 94 | |
Vincent Hou | 22f03c7 | 2012-08-24 17:55:13 +0800 | [diff] [blame] | 95 | FLOAT_CLIENTS = { |
| 96 | "json": FloatingIPsClientJSON, |
| 97 | "xml": FloatingIPsClientXML, |
| 98 | } |
| 99 | |
Matthew Treinish | 9854d5b | 2012-09-20 10:22:13 -0400 | [diff] [blame] | 100 | VOLUMES_CLIENTS = { |
| 101 | "json": VolumesClientJSON, |
| 102 | "xml": VolumesClientXML, |
| 103 | } |
| 104 | |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 105 | ADMIN_CLIENT = { |
| 106 | "json": AdminClientJSON, |
| 107 | "xml": AdminClientXML, |
| 108 | } |
| 109 | |
| 110 | TOKEN_CLIENT = { |
| 111 | "json": TokenClientJSON, |
| 112 | "xml": TokenClientXML, |
| 113 | } |
| 114 | |
Vincent Hou | ead03dc | 2012-08-24 21:35:11 +0800 | [diff] [blame^] | 115 | SECURITY_GROUPS_CLIENT = { |
| 116 | "json": SecurityGroupsClientJSON, |
| 117 | "xml": SecurityGroupsClientXML, |
| 118 | } |
| 119 | |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 120 | |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 121 | class Manager(object): |
| 122 | |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 123 | """ |
| 124 | Top level manager for OpenStack Compute clients |
| 125 | """ |
| 126 | |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 127 | def __init__(self, username=None, password=None, tenant_name=None, |
| 128 | interface='json'): |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 129 | """ |
| 130 | We allow overriding of the credentials used within the various |
| 131 | client classes managed by the Manager object. Left as None, the |
| 132 | standard username/password/tenant_name is used. |
| 133 | |
| 134 | :param username: Override of the username |
| 135 | :param password: Override of the password |
| 136 | :param tenant_name: Override of the tenant name |
| 137 | """ |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 138 | self.config = config.TempestConfig() |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame] | 139 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 140 | # If no creds are provided, we fall back on the defaults |
| 141 | # in the config file for the Compute API. |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 142 | self.username = username or self.config.compute.username |
| 143 | self.password = password or self.config.compute.password |
| 144 | self.tenant_name = tenant_name or self.config.compute.tenant_name |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 145 | |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 146 | if None in (self.username, self.password, self.tenant_name): |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 147 | msg = ("Missing required credentials. " |
| 148 | "username: %(username)s, password: %(password)s, " |
| 149 | "tenant_name: %(tenant_name)s") % locals() |
| 150 | raise exceptions.InvalidConfiguration(msg) |
| 151 | |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 152 | self.auth_url = self.config.identity.auth_url |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 153 | |
| 154 | if self.config.identity.strategy == 'keystone': |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 155 | client_args = (self.config, self.username, self.password, |
| 156 | self.auth_url, self.tenant_name) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 157 | else: |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 158 | client_args = (self.config, self.username, self.password, |
| 159 | self.auth_url) |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 160 | |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 161 | try: |
| 162 | self.servers_client = SERVERS_CLIENTS[interface](*client_args) |
Matthew Treinish | 3363446 | 2012-08-16 16:51:23 -0400 | [diff] [blame] | 163 | self.limits_client = LIMITS_CLIENTS[interface](*client_args) |
Mauro S. M. Rodrigues | 6e37324 | 2012-08-27 18:59:19 -0400 | [diff] [blame] | 164 | self.images_client = IMAGES_CLIENTS[interface](*client_args) |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 165 | self.keypairs_client = KEYPAIRS_CLIENTS[interface](*client_args) |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 166 | self.flavors_client = FLAVORS_CLIENTS[interface](*client_args) |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 167 | ext_cli = EXTENSIONS_CLIENTS[interface](*client_args) |
| 168 | self.extensions_client = ext_cli |
| 169 | vol_ext_cli = VOLUMES_EXTENSIONS_CLIENTS[interface](*client_args) |
| 170 | self.volumes_extensions_client = vol_ext_cli |
Vincent Hou | 22f03c7 | 2012-08-24 17:55:13 +0800 | [diff] [blame] | 171 | self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args) |
Matthew Treinish | 9854d5b | 2012-09-20 10:22:13 -0400 | [diff] [blame] | 172 | self.volumes_client = VOLUMES_CLIENTS[interface](*client_args) |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 173 | self.admin_client = ADMIN_CLIENT[interface](*client_args) |
| 174 | self.token_client = TOKEN_CLIENT[interface](self.config) |
Vincent Hou | ead03dc | 2012-08-24 21:35:11 +0800 | [diff] [blame^] | 175 | self.security_groups_client = \ |
| 176 | SECURITY_GROUPS_CLIENT[interface](*client_args) |
Dan Smith | cf8fab6 | 2012-08-14 08:03:48 -0700 | [diff] [blame] | 177 | except KeyError: |
| 178 | msg = "Unsupported interface type `%s'" % interface |
| 179 | raise exceptions.InvalidConfiguration(msg) |
rajalakshmi-ganesan | 72ea31a | 2012-05-25 11:59:10 +0530 | [diff] [blame] | 180 | self.console_outputs_client = ConsoleOutputsClient(*client_args) |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 181 | self.network_client = NetworkClient(*client_args) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 182 | |
| 183 | |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 184 | class AltManager(Manager): |
| 185 | |
| 186 | """ |
| 187 | Manager object that uses the alt_XXX credentials for its |
| 188 | managed client objects |
| 189 | """ |
| 190 | |
| 191 | def __init__(self): |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 192 | conf = config.TempestConfig() |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 193 | super(AltManager, self).__init__(conf.compute.alt_username, |
| 194 | conf.compute.alt_password, |
| 195 | conf.compute.alt_tenant_name) |
| 196 | |
| 197 | |
| 198 | class AdminManager(Manager): |
| 199 | |
| 200 | """ |
| 201 | Manager object that uses the alt_XXX credentials for its |
| 202 | managed client objects |
| 203 | """ |
| 204 | |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 205 | def __init__(self, interface='json'): |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 206 | conf = config.TempestConfig() |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 207 | super(AdminManager, self).__init__(conf.compute_admin.username, |
| 208 | conf.compute_admin.password, |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 209 | conf.compute_admin.tenant_name, |
| 210 | interface=interface) |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 211 | |
| 212 | |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 213 | class ServiceManager(object): |
| 214 | |
| 215 | """ |
| 216 | Top-level object housing clients for OpenStack APIs |
| 217 | """ |
| 218 | |
| 219 | def __init__(self): |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 220 | self.config = config.TempestConfig() |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 221 | self.services = {} |
| 222 | self.services['image'] = image_service.Service(self.config) |
| 223 | self.images = self.services['image'] |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 224 | |
| 225 | |
| 226 | class IdentityManager(Manager): |
| 227 | |
| 228 | """ |
| 229 | Manager object that uses the alt_XXX credentials for its |
| 230 | managed client objects |
| 231 | """ |
| 232 | |
| 233 | def __init__(self, interface='json'): |
| 234 | conf = config.TempestConfig() |
| 235 | super(IdentityManager, self).__init__(conf.identity_admin.username, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 236 | conf.identity_admin.password, |
| 237 | conf.identity_admin.tenant_name, |
| 238 | interface) |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 239 | |
| 240 | |
| 241 | class IdentityNaManager(Manager): |
| 242 | |
| 243 | """ |
| 244 | Manager object that uses the alt_XXX credentials for its |
| 245 | managed client objects |
| 246 | """ |
| 247 | |
| 248 | def __init__(self, interface='json'): |
| 249 | conf = config.TempestConfig() |
| 250 | super(IdentityNaManager, self).__init__(conf.compute.username, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 251 | conf.compute.password, |
| 252 | conf.compute.tenant_name, |
| 253 | interface) |