1 from keystoneclient.v2_0 import client as keystone_client
2 from glance import client as glance_client
3 from novaclient.v1_1 import client as nova_client
4 from PLC.Config import Config
5 from PLC.Logger import logger
7 def parse_novarc(filename):
9 f = open(filename, 'r')
12 line = line.replace('export', '').strip()
13 parts = line.split('=')
15 value = parts[1].replace("\'", "")
16 value = value.replace('\"', '')
17 opts[parts[0]] = value
25 def __init__(self, username=None, password=None, tenant=None, url=None, config=None, *args, **kwds):
27 config = Config(config)
30 self.username = config.nova_admin_user
31 self.password = config.nova_admin_password
32 self.tenant = config.nova_admin_tenant
33 self.url = config.nova_url
36 self.username = username
38 self.password = password
44 class KeystoneClient(Client):
45 def __init__(self, *args, **kwds):
46 Client.__init__(self, *args, **kwds)
47 self.client = keystone_client.Client(username=self.username,
48 password=self.password,
49 tenant_name=self.tenant,
52 def connect(self, *args, **kwds):
53 self.__init__(*args, **kwds)
55 def __getattr__(self, name):
56 return getattr(self.client, name)
59 class GlanceClient(Client):
60 def __init__(self, *args, **kwds):
61 Client.__init__(self, *args, **kwds)
62 self.client = glance_client.get_client(host='0.0.0.0',
63 username=self.username,
64 password=self.password,
67 def __getattr__(self, name):
68 return getattr(self.client, name)
70 class NovaClient(Client):
71 def __init__(self, *args, **kwds):
72 Client.__init__(self, *args, **kwds)
73 self.client = nova_client.Client(username=self.username,
74 api_key=self.password,
75 project_id=self.tenant,
79 service_type='compute',
83 def connect(self, *args, **kwds):
84 self.__init__(*args, **kwds)
86 def __getattr__(self, name):
87 return getattr(self.client, name)
91 A simple native shell to a nova backend.
92 This class can receive all nova calls to the underlying testbed
95 def __init__ ( self, *args, **kwds) :
96 # instantiate managers
97 self.keystone = KeystoneClient(*args, **kwds)
98 self.glance = GlanceClient(*args, **kwds)
99 self.nova = NovaClient(*args, **kwds)
101 def authenticate(self):
102 return self.keystone.authenticate()