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