blob: e892082f2e858ddd362717c96ce17c9d76f8999b [file] [log] [blame]
Jay Pipes3f981df2012-03-27 18:59:44 -04001# 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
18import logging
19
Jay Pipesf38eaac2012-06-21 13:37:35 -040020from tempest import config
Daryl Walleck587385b2012-03-03 13:00:26 -060021from tempest import exceptions
Jay Pipes50677282012-01-06 15:39:20 -050022from tempest.services.image import service as image_service
Unmesh Gurjar44986832012-05-08 19:57:10 +053023from tempest.services.network.json.network_client import NetworkClient
Daryl Wallecked8bef32011-12-05 23:02:08 -060024from tempest.services.nova.json.images_client import ImagesClient
25from tempest.services.nova.json.flavors_client import FlavorsClient
26from tempest.services.nova.json.servers_client import ServersClient
27from tempest.services.nova.json.limits_client import LimitsClient
donald-ngo20b6bca2011-12-15 13:35:12 -080028from tempest.services.nova.json.extensions_client import ExtensionsClient
Ravikumar Venkatesanaf7ab1c2012-01-17 12:54:22 -080029from tempest.services.nova.json.security_groups_client \
30import SecurityGroupsClient
sapan-konaed37d732012-01-18 22:52:12 +053031from tempest.services.nova.json.floating_ips_client import FloatingIPsClient
kavan-patil2eb350f2012-01-19 11:17:26 +000032from tempest.services.nova.json.keypairs_client import KeyPairsClient
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053033from tempest.services.nova.json.volumes_client import VolumesClient
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +053034from tempest.services.nova.json.console_output_client \
35import ConsoleOutputsClient
Daryl Walleck1465d612011-11-02 02:22:15 -050036
Jay Pipes3f981df2012-03-27 18:59:44 -040037LOG = logging.getLogger(__name__)
38
Daryl Walleck1465d612011-11-02 02:22:15 -050039
40class Manager(object):
41
Jay Pipes3f981df2012-03-27 18:59:44 -040042 """
43 Top level manager for OpenStack Compute clients
44 """
45
Jay Pipesff10d552012-04-06 14:18:50 -040046 def __init__(self, username=None, password=None, tenant_name=None):
47 """
48 We allow overriding of the credentials used within the various
49 client classes managed by the Manager object. Left as None, the
50 standard username/password/tenant_name is used.
51
52 :param username: Override of the username
53 :param password: Override of the password
54 :param tenant_name: Override of the tenant name
55 """
Jay Pipesf38eaac2012-06-21 13:37:35 -040056 self.config = config.TempestConfig()
Rohit Karajgie1b050d2011-12-02 16:13:18 -080057
Jay Pipesf38eaac2012-06-21 13:37:35 -040058 # If no creds are provided, we fall back on the defaults
59 # in the config file for the Compute API.
Jay Pipesff10d552012-04-06 14:18:50 -040060 username = username or self.config.compute.username
61 password = password or self.config.compute.password
62 tenant_name = tenant_name or self.config.compute.tenant_name
Daryl Walleckced8eb82012-03-19 13:52:37 -050063
Jay Pipes3f981df2012-03-27 18:59:44 -040064 if None in (username, password, tenant_name):
65 msg = ("Missing required credentials. "
66 "username: %(username)s, password: %(password)s, "
67 "tenant_name: %(tenant_name)s") % locals()
68 raise exceptions.InvalidConfiguration(msg)
69
Daryl Walleck587385b2012-03-03 13:00:26 -060070 auth_url = self.config.identity.auth_url
71
72 if self.config.identity.strategy == 'keystone':
73 client_args = (self.config, username, password, auth_url,
74 tenant_name)
Daryl Walleck1465d612011-11-02 02:22:15 -050075 else:
Daryl Walleck587385b2012-03-03 13:00:26 -060076 client_args = (self.config, username, password, auth_url)
77
78 self.servers_client = ServersClient(*client_args)
79 self.flavors_client = FlavorsClient(*client_args)
80 self.images_client = ImagesClient(*client_args)
81 self.limits_client = LimitsClient(*client_args)
82 self.extensions_client = ExtensionsClient(*client_args)
83 self.keypairs_client = KeyPairsClient(*client_args)
84 self.security_groups_client = SecurityGroupsClient(*client_args)
85 self.floating_ips_client = FloatingIPsClient(*client_args)
rajalakshmi-ganesanddd9e0e2012-03-21 00:49:22 +053086 self.volumes_client = VolumesClient(*client_args)
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +053087 self.console_outputs_client = ConsoleOutputsClient(*client_args)
Unmesh Gurjar44986832012-05-08 19:57:10 +053088 self.network_client = NetworkClient(*client_args)
Jay Pipes50677282012-01-06 15:39:20 -050089
90
Jay Pipesff10d552012-04-06 14:18:50 -040091class AltManager(Manager):
92
93 """
94 Manager object that uses the alt_XXX credentials for its
95 managed client objects
96 """
97
98 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -040099 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400100 super(AltManager, self).__init__(conf.compute.alt_username,
101 conf.compute.alt_password,
102 conf.compute.alt_tenant_name)
103
104
105class AdminManager(Manager):
106
107 """
108 Manager object that uses the alt_XXX credentials for its
109 managed client objects
110 """
111
112 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400113 conf = config.TempestConfig()
Jay Pipesff10d552012-04-06 14:18:50 -0400114 super(AdminManager, self).__init__(conf.compute_admin.username,
115 conf.compute_admin.password,
116 conf.compute_admin.tenant_name)
Jay Pipesff10d552012-04-06 14:18:50 -0400117
118
Jay Pipes50677282012-01-06 15:39:20 -0500119class ServiceManager(object):
120
121 """
122 Top-level object housing clients for OpenStack APIs
123 """
124
125 def __init__(self):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400126 self.config = config.TempestConfig()
Jay Pipes50677282012-01-06 15:39:20 -0500127 self.services = {}
128 self.services['image'] = image_service.Service(self.config)
129 self.images = self.services['image']