3 from keystoneclient.v2_0 import client as keystone_client
4 #from glance import client as glance_client
6 from novaclient.v1_1 import client as nova_client
7 from neutronclient.v2_0 import client as quantum_client
8 from nova.db.sqlalchemy import api as nova_db_api
9 from nova.context import get_admin_context
14 from planetstack.config import Config
16 def require_enabled(callable):
17 def wrapper(*args, **kwds):
19 return callable(*args, **kwds)
24 def parse_novarc(filename):
26 f = open(filename, 'r')
29 line = line.replace('export', '').strip()
30 parts = line.split('=')
32 value = parts[1].replace("\'", "")
33 value = value.replace('\"', '')
34 opts[parts[0]] = value
41 def __init__(self, username=None, password=None, tenant=None, url=None, token=None, endpoint=None, deployment=None, admin=True, *args, **kwds):
43 self.has_openstack = has_openstack
44 self.url = deployment.auth_url
46 self.username = deployment.admin_user
47 self.password = deployment.admin_password
48 self.tenant = deployment.admin_tenant
55 self.username = username
57 self.password = password
65 self.endpoint = endpoint
67 #if '@' in self.username:
68 # self.username = self.username[:self.username.index('@')]
70 class KeystoneClient(Client):
71 def __init__(self, *args, **kwds):
72 Client.__init__(self, *args, **kwds)
74 self.client = keystone_client.Client(username=self.username,
75 password=self.password,
76 tenant_name=self.tenant,
81 def connect(self, *args, **kwds):
82 self.__init__(*args, **kwds)
85 def __getattr__(self, name):
86 return getattr(self.client, name)
89 class GlanceClient(Client):
90 def __init__(self, *args, **kwds):
91 Client.__init__(self, *args, **kwds)
93 self.client = glanceclient.get_client(host='0.0.0.0',
94 username=self.username,
95 password=self.password,
99 def __getattr__(self, name):
100 return getattr(self.client, name)
102 class GlanceClientNew(Client):
103 def __init__(self, version, endpoint, token, *args, **kwds):
104 Client.__init__(self, *args, **kwds)
106 self.client = glanceclient.Client(version, endpoint=endpoint, token=token)
109 def __getattr__(self, name):
110 return getattr(self.client, name)
112 class NovaClient(Client):
113 def __init__(self, *args, **kwds):
114 Client.__init__(self, *args, **kwds)
116 self.client = nova_client.Client(username=self.username,
117 api_key=self.password,
118 project_id=self.tenant,
122 service_type='compute',
127 def connect(self, *args, **kwds):
128 self.__init__(*args, **kwds)
131 def __getattr__(self, name):
132 return getattr(self.client, name)
134 class NovaDB(Client):
135 def __init__(self, *args, **kwds):
136 Client.__init__(self, *args, **kwds)
138 self.ctx = get_admin_context()
139 nova_db_api.FLAGS(default_config_files=['/etc/nova/nova.conf'])
140 self.client = nova_db_api
144 def connect(self, *args, **kwds):
145 self.__init__(*args, **kwds)
148 def __getattr__(self, name):
149 return getattr(self.client, name)
151 class QuantumClient(Client):
152 def __init__(self, *args, **kwds):
153 Client.__init__(self, *args, **kwds)
155 self.client = quantum_client.Client(username=self.username,
156 password=self.password,
157 tenant_name=self.tenant,
160 def connect(self, *args, **kwds):
161 self.__init__(*args, **kwds)
164 def __getattr__(self, name):
165 return getattr(self.client, name)
167 class OpenStackClient:
169 A simple native shell to the openstack backend services.
170 This class can receive all nova calls to the underlying testbed
173 def __init__ ( self, *args, **kwds) :
174 # instantiate managers
175 self.keystone = KeystoneClient(*args, **kwds)
176 url_parsed = urlparse.urlparse(self.keystone.url)
177 hostname = url_parsed.netloc.split(':')[0]
178 token = self.keystone.client.tokens.authenticate(username=self.keystone.username, password=self.keystone.password, tenant_name=self.keystone.tenant)
179 #self.glance = GlanceClient(*args, **kwds)
181 self.glanceclient = GlanceClientNew('1', endpoint='http://%s:9292' % hostname, token=token.id, **kwds)
182 self.nova = NovaClient(*args, **kwds)
183 # self.nova_db = NovaDB(*args, **kwds)
184 self.quantum = QuantumClient(*args, **kwds)
188 def connect(self, *args, **kwds):
189 self.__init__(*args, **kwds)
192 def authenticate(self):
193 return self.keystone.authenticate()