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