1 from sfa.util.sfalogging import logger
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 sfa.util.config import Config
8 def parse_novarc(filename):
10 f = open(filename, 'r')
13 line = line.replace('export', '').strip()
14 parts = line.split('=')
16 value = parts[1].replace("\'", "")
17 value = value.replace('\"', '')
18 opts[parts[0]] = value
26 def __init__(self, username=None, password=None, tenant=None, url=None, config=None):
29 opts = parse_novarc(config.SFA_NOVA_NOVARC)
31 opts['OS_USERNAME'] = username
33 opts['OS_PASSWORD'] = password
35 opts['OS_TENANT_NAME'] = tenant
37 opts['OS_AUTH_URL'] = url
39 self.client = keystone_client.Client(username=opts.get('OS_USERNAME'),
40 password=opts.get('OS_PASSWORD'),
41 tenant_name=opts.get('OS_TENANT_NAME'),
42 auth_url=opts.get('OS_AUTH_URL'))
44 def connect(self, *args, **kwds):
45 self.__init__(*args, **kwds)
47 def __getattr__(self, name):
48 return getattr(self.client, name)
52 def __init__(self, config=None):
55 opts = parse_novarc(config.SFA_NOVA_NOVARC)
56 self.client = glance_client.get_client(host='0.0.0.0',
57 username=opts.get('OS_USERNAME'),
58 password=opts.get('OS_PASSWORD'),
59 tenant=opts.get('OS_TENANT_NAME'),
60 auth_url=opts.get('OS_AUTH_URL'))
61 def __getattr__(self, name):
62 return getattr(self.client, name)
65 def __init__(self, username=None, password=None, tenant=None, url=None, config=None):
68 opts = parse_novarc(config.SFA_NOVA_NOVARC)
70 opts['OS_USERNAME'] = username
72 opts['OS_PASSWORD'] = password
74 opts['OS_TENANT_NAME'] = tenant
76 opts['OS_AUTH_URL'] = url
78 self.client = nova_client.Client(username=opts.get('OS_USERNAME'),
79 api_key=opts.get('OS_PASSWORD'),
80 project_id=opts.get('OS_TENANT_NAME'),
81 auth_url=opts.get('OS_AUTH_URL'),
84 service_type='compute',
88 def connect(self, *args, **kwds):
89 self.__init__(*args, **kwds)
91 def __getattr__(self, name):
92 return getattr(self.client, name)