initial checkin
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 26 Jun 2012 01:19:09 +0000 (21:19 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 26 Jun 2012 01:19:09 +0000 (21:19 -0400)
sfa/openstack/client.py [new file with mode: 0644]

diff --git a/sfa/openstack/client.py b/sfa/openstack/client.py
new file mode 100644 (file)
index 0000000..5900339
--- /dev/null
@@ -0,0 +1,40 @@
+from sfa.util.sfalogging import logger
+from glance import client as glance_client
+from sfa.util.config import Config
+
+
+def parse_novarc(filename):
+    opts = {}
+    f = open(filename, 'r')
+    for line in f:
+        try:
+            line = line.replace('export', '').strip()
+            parts = line.split('=')
+            if len(parts) > 1:
+                value = parts[1].replace("\'", "")
+                value = value.replace('\"', '') 
+                opts[parts[0]] = value
+        except:
+            pass
+    f.close()
+    return opts
+
+
+class GlanceClient:
+    def __init__(self, config):
+        if not config:
+            config = Config()
+        opts = parse_novarc(config.SFA_NOVA_NOVARC)
+
+        self.client = glance_client.get_client(host='0.0.0.0',
+                                               username=opts.get('OS_USERNAME'),
+                                               password=opts.get('OS_PASSWORD'),
+                                               tenant=opts.get('OS_TENANT_NAME'),
+                                               auth_url=opts.get('OS_AUTH_URL'))
+
+    def __getattr__(self, name):
+        return getattr(self.client, name)
+
+
+
+