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 if '@' in self.username:
45 self.username = self.username[:self.username.index('@')]
47 class KeystoneClient(Client):
48 def __init__(self, *args, **kwds):
49 Client.__init__(self, *args, **kwds)
50 self.client = keystone_client.Client(username=self.username,
51 password=self.password,
52 tenant_name=self.tenant,
55 def connect(self, *args, **kwds):
56 self.__init__(*args, **kwds)
58 def __getattr__(self, name):
59 return getattr(self.client, name)
62 class GlanceClient(Client):
63 def __init__(self, *args, **kwds):
64 Client.__init__(self, *args, **kwds)
65 self.client = glance_client.get_client(host='0.0.0.0',
66 username=self.username,
67 password=self.password,
70 def __getattr__(self, name):
71 return getattr(self.client, name)
73 class NovaClient(Client):
74 def __init__(self, *args, **kwds):
75 Client.__init__(self, *args, **kwds)
76 self.client = nova_client.Client(username=self.username,
77 api_key=self.password,
78 project_id=self.tenant,
82 service_type='compute',
86 def connect(self, *args, **kwds):
87 self.__init__(*args, **kwds)
89 def __getattr__(self, name):
90 return getattr(self.client, name)
94 A simple native shell to a nova backend.
95 This class can receive all nova calls to the underlying testbed
98 def __init__ ( self, *args, **kwds) :
99 # instantiate managers
100 self.keystone = KeystoneClient(*args, **kwds)
101 self.glance = GlanceClient(*args, **kwds)
102 self.nova = NovaClient(*args, **kwds)
104 def authenticate(self):
105 return self.keystone.authenticate()