2 from keystoneclient.v2_0 import client as keystone_client
3 from glance import client as glance_client
4 from novaclient.v1_1 import client as nova_client
5 from quantumclient.v2_0 import client as quantum_client
6 from nova.db.sqlalchemy import api as nova_db_api
7 from nova.context import get_admin_context
12 from planetstack.config import Config
14 def require_enabled(callable):
15 def wrapper(*args, **kwds):
17 return callable(*args, **kwds)
22 def parse_novarc(filename):
24 f = open(filename, 'r')
27 line = line.replace('export', '').strip()
28 parts = line.split('=')
30 value = parts[1].replace("\'", "")
31 value = value.replace('\"', '')
32 opts[parts[0]] = value
39 def __init__(self, username=None, password=None, tenant=None, url=None, config=None, *args, **kwds):
41 config = Config(config)
44 self.has_openstack = has_openstack
45 self.username = config.nova_admin_user
46 self.password = config.nova_admin_password
47 self.tenant = config.nova_admin_tenant
48 self.url = config.nova_url
51 self.username = username
53 self.password = password
59 if '@' in self.username:
60 self.username = self.username[:self.username.index('@')]
62 class KeystoneClient(Client):
63 def __init__(self, *args, **kwds):
64 Client.__init__(self, *args, **kwds)
66 self.client = keystone_client.Client(username=self.username,
67 password=self.password,
68 tenant_name=self.tenant,
72 def connect(self, *args, **kwds):
73 self.__init__(*args, **kwds)
76 def __getattr__(self, name):
77 return getattr(self.client, name)
80 class GlanceClient(Client):
81 def __init__(self, *args, **kwds):
82 Client.__init__(self, *args, **kwds)
84 self.client = glance_client.get_client(host='0.0.0.0',
85 username=self.username,
86 password=self.password,
90 def __getattr__(self, name):
91 return getattr(self.client, name)
93 class NovaClient(Client):
94 def __init__(self, *args, **kwds):
95 Client.__init__(self, *args, **kwds)
97 self.client = nova_client.Client(username=self.username,
98 api_key=self.password,
99 project_id=self.tenant,
103 service_type='compute',
108 def connect(self, *args, **kwds):
109 self.__init__(*args, **kwds)
112 def __getattr__(self, name):
113 return getattr(self.client, name)
115 class NovaDB(Client):
116 def __init__(self, *args, **kwds):
117 Client.__init__(self, *args, **kwds)
119 self.ctx = get_admin_context()
120 api.FLAGS(default_config_files=['/etc/nova/nova.conf'])
121 self.client = nova_db_api
125 def connect(self, *args, **kwds):
126 self.__init__(*args, **kwds)
129 def __getattr__(self, name):
130 return getattr(self.client, name)
132 class QuantumClient(Client):
133 def __init__(self, *args, **kwds):
134 Client.__init__(self, *args, **kwds)
136 self.client = quantum_client.Client(username=self.username,
137 password=self.password,
138 tenant_name=self.tenant,
141 def connect(self, *args, **kwds):
142 self.__init__(*args, **kwds)
145 def __getattr__(self, name):
146 return getattr(self.client, name)
148 class OpenStackClient:
150 A simple native shell to the openstack backend services.
151 This class can receive all nova calls to the underlying testbed
154 def __init__ ( self, *args, **kwds) :
155 # instantiate managers
156 self.keystone = KeystoneClient(*args, **kwds)
157 self.glance = GlanceClient(*args, **kwds)
158 self.nova = NovaClient(*args, **kwds)
159 self.nova_db = NovaDB(*args, **kwds)
160 self.quantum = QuantumClient(*args, **kwds)
163 def connect(self, *args, **kwds):
164 self.__init__(*args, **kwds)
167 def authenticate(self):
168 return self.keystone.authenticate()