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 | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 20 | import tempest.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 |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 23 | from tempest.services.nova.json.images_client import ImagesClient |
| 24 | from tempest.services.nova.json.flavors_client import FlavorsClient |
| 25 | from tempest.services.nova.json.servers_client import ServersClient |
| 26 | from tempest.services.nova.json.limits_client import LimitsClient |
donald-ngo | 20b6bca | 2011-12-15 13:35:12 -0800 | [diff] [blame] | 27 | from tempest.services.nova.json.extensions_client import ExtensionsClient |
Ravikumar Venkatesan | af7ab1c | 2012-01-17 12:54:22 -0800 | [diff] [blame] | 28 | from tempest.services.nova.json.security_groups_client \ |
| 29 | import SecurityGroupsClient |
sapan-kona | ed37d73 | 2012-01-18 22:52:12 +0530 | [diff] [blame] | 30 | from tempest.services.nova.json.floating_ips_client import FloatingIPsClient |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 31 | from tempest.services.nova.json.keypairs_client import KeyPairsClient |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 32 | from tempest.services.nova.json.volumes_client import VolumesClient |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 33 | |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 34 | LOG = logging.getLogger(__name__) |
| 35 | |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 36 | |
| 37 | class Manager(object): |
| 38 | |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 39 | """ |
| 40 | Top level manager for OpenStack Compute clients |
| 41 | """ |
| 42 | |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 43 | def __init__(self, username=None, password=None, tenant_name=None): |
| 44 | """ |
| 45 | We allow overriding of the credentials used within the various |
| 46 | client classes managed by the Manager object. Left as None, the |
| 47 | standard username/password/tenant_name is used. |
| 48 | |
| 49 | :param username: Override of the username |
| 50 | :param password: Override of the password |
| 51 | :param tenant_name: Override of the tenant name |
| 52 | """ |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 53 | self.config = tempest.config.TempestConfig() |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame] | 54 | |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 55 | username = username or self.config.compute.username |
| 56 | password = password or self.config.compute.password |
| 57 | tenant_name = tenant_name or self.config.compute.tenant_name |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 58 | |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 59 | if None in (username, password, tenant_name): |
| 60 | msg = ("Missing required credentials. " |
| 61 | "username: %(username)s, password: %(password)s, " |
| 62 | "tenant_name: %(tenant_name)s") % locals() |
| 63 | raise exceptions.InvalidConfiguration(msg) |
| 64 | |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 65 | auth_url = self.config.identity.auth_url |
| 66 | |
| 67 | if self.config.identity.strategy == 'keystone': |
| 68 | client_args = (self.config, username, password, auth_url, |
| 69 | tenant_name) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 70 | else: |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 71 | client_args = (self.config, username, password, auth_url) |
| 72 | |
| 73 | self.servers_client = ServersClient(*client_args) |
| 74 | self.flavors_client = FlavorsClient(*client_args) |
| 75 | self.images_client = ImagesClient(*client_args) |
| 76 | self.limits_client = LimitsClient(*client_args) |
| 77 | self.extensions_client = ExtensionsClient(*client_args) |
| 78 | self.keypairs_client = KeyPairsClient(*client_args) |
| 79 | self.security_groups_client = SecurityGroupsClient(*client_args) |
| 80 | self.floating_ips_client = FloatingIPsClient(*client_args) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 81 | self.volumes_client = VolumesClient(*client_args) |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 82 | |
| 83 | |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 84 | class AltManager(Manager): |
| 85 | |
| 86 | """ |
| 87 | Manager object that uses the alt_XXX credentials for its |
| 88 | managed client objects |
| 89 | """ |
| 90 | |
| 91 | def __init__(self): |
| 92 | conf = tempest.config.TempestConfig() |
| 93 | super(AltManager, self).__init__(conf.compute.alt_username, |
| 94 | conf.compute.alt_password, |
| 95 | conf.compute.alt_tenant_name) |
| 96 | |
| 97 | |
| 98 | class AdminManager(Manager): |
| 99 | |
| 100 | """ |
| 101 | Manager object that uses the alt_XXX credentials for its |
| 102 | managed client objects |
| 103 | """ |
| 104 | |
| 105 | def __init__(self): |
| 106 | conf = tempest.config.TempestConfig() |
| 107 | super(AdminManager, self).__init__(conf.compute_admin.username, |
| 108 | conf.compute_admin.password, |
| 109 | conf.compute_admin.tenant_name) |
| 110 | # TODO(jaypipes): Add Admin-Only client class construction below... |
| 111 | |
| 112 | |
Jay Pipes | 5067728 | 2012-01-06 15:39:20 -0500 | [diff] [blame] | 113 | class ServiceManager(object): |
| 114 | |
| 115 | """ |
| 116 | Top-level object housing clients for OpenStack APIs |
| 117 | """ |
| 118 | |
| 119 | def __init__(self): |
| 120 | self.config = tempest.config.TempestConfig() |
| 121 | self.services = {} |
| 122 | self.services['image'] = image_service.Service(self.config) |
| 123 | self.images = self.services['image'] |