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