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
10 from planetstack.config import Config
12 def require_enabled(callable):
13 def wrapper(*args, **kwds):
15 return callable(*args, **kwds)
20 def parse_novarc(filename):
22 f = open(filename, 'r')
25 line = line.replace('export', '').strip()
26 parts = line.split('=')
28 value = parts[1].replace("\'", "")
29 value = value.replace('\"', '')
30 opts[parts[0]] = value
37 def __init__(self, username=None, password=None, tenant=None, url=None, config=None, *args, **kwds):
39 config = Config(config)
42 self.has_openstack = has_openstack
43 self.username = config.nova_admin_user
44 self.password = config.nova_admin_password
45 self.tenant = config.nova_admin_tenant
46 self.url = config.nova_url
49 self.username = username
51 self.password = password
57 if '@' in self.username:
58 self.username = self.username[:self.username.index('@')]
60 class KeystoneClient(Client):
61 def __init__(self, *args, **kwds):
62 Client.__init__(self, *args, **kwds)
64 self.client = keystone_client.Client(username=self.username,
65 password=self.password,
66 tenant_name=self.tenant,
70 def connect(self, *args, **kwds):
71 self.__init__(*args, **kwds)
74 def __getattr__(self, name):
75 return getattr(self.client, name)
78 class GlanceClient(Client):
79 def __init__(self, *args, **kwds):
80 Client.__init__(self, *args, **kwds)
82 self.client = glance_client.get_client(host='0.0.0.0',
83 username=self.username,
84 password=self.password,
88 def __getattr__(self, name):
89 return getattr(self.client, name)
91 class NovaClient(Client):
92 def __init__(self, *args, **kwds):
93 Client.__init__(self, *args, **kwds)
95 self.client = nova_client.Client(username=self.username,
96 api_key=self.password,
97 project_id=self.tenant,
101 service_type='compute',
106 def connect(self, *args, **kwds):
107 self.__init__(*args, **kwds)
110 def __getattr__(self, name):
111 return getattr(self.client, name)
113 class QuantumClient(Client):
114 def __init__(self, *args, **kwds):
115 Client.__init__(self, *args, **kwds)
117 self.client = quantum_client.Client(username=self.username,
118 password=self.password,
119 tenant_name=self.tenant,
122 def connect(self, *args, **kwds):
123 self.__init__(*args, **kwds)
126 def __getattr__(self, name):
127 return getattr(self.client, name)
129 class OpenStackClient:
131 A simple native shell to the openstack backend services.
132 This class can receive all nova calls to the underlying testbed
135 def __init__ ( self, *args, **kwds) :
136 # instantiate managers
137 self.keystone = KeystoneClient(*args, **kwds)
138 self.glance = GlanceClient(*args, **kwds)
139 self.nova = NovaClient(*args, **kwds)
140 self.quantum = QuantumClient(*args, **kwds)
143 def connect(self, *args, **kwds):
144 self.__init__(*args, **kwds)
147 def authenticate(self):
148 return self.keystone.authenticate()