initial checkin
[sfa.git] / sfa / openstack / client.py
1 from sfa.util.sfalogging import logger
2 from glance import client as glance_client
3 from sfa.util.config import Config
4
5
6 def parse_novarc(filename):
7     opts = {}
8     f = open(filename, 'r')
9     for line in f:
10         try:
11             line = line.replace('export', '').strip()
12             parts = line.split('=')
13             if len(parts) > 1:
14                 value = parts[1].replace("\'", "")
15                 value = value.replace('\"', '') 
16                 opts[parts[0]] = value
17         except:
18             pass
19     f.close()
20     return opts
21
22
23 class GlanceClient:
24     def __init__(self, config):
25         if not config:
26             config = Config()
27         opts = parse_novarc(config.SFA_NOVA_NOVARC)
28
29         self.client = glance_client.get_client(host='0.0.0.0',
30                                                username=opts.get('OS_USERNAME'),
31                                                password=opts.get('OS_PASSWORD'),
32                                                tenant=opts.get('OS_TENANT_NAME'),
33                                                auth_url=opts.get('OS_AUTH_URL'))
34
35     def __getattr__(self, name):
36         return getattr(self.client, name)
37
38
39
40