initialize glance client with ca_ssl_cert
[plstackapi.git] / planetstack / openstack / client.py
index d776ec9..0aa6c7d 100644 (file)
@@ -5,8 +5,6 @@ try:
     import glanceclient
     from novaclient.v1_1 import client as nova_client
     from neutronclient.v2_0 import client as quantum_client
-    from nova.db.sqlalchemy import api as nova_db_api 
-    from nova.context import get_admin_context
     has_openstack = True
 except:
     has_openstack = False
@@ -40,14 +38,12 @@ def parse_novarc(filename):
 class Client:
     def __init__(self, username=None, password=None, tenant=None, url=None, token=None, endpoint=None, controller=None, admin=True, *args, **kwds):
        
-        deployment = controller
-
         self.has_openstack = has_openstack
-        self.url = deployment.auth_url
+        self.url = controller.auth_url
         if admin:
-            self.username = deployment.admin_user
-            self.password = deployment.admin_password
-            self.tenant = deployment.admin_tenant
+            self.username = controller.admin_user
+            self.password = controller.admin_password
+            self.tenant = controller.admin_tenant
         else:
             self.username = None
             self.password = None
@@ -88,7 +84,7 @@ class KeystoneClient(Client):
         return getattr(self.client, name)
 
 
-class GlanceClient(Client):
+class Glance(Client):
     def __init__(self, *args, **kwds):
         Client.__init__(self, *args, **kwds)
         if has_openstack:
@@ -101,11 +97,15 @@ class GlanceClient(Client):
     def __getattr__(self, name):
         return getattr(self.client, name)
 
-class GlanceClientNew(Client):
-    def __init__(self, version, endpoint, token, *args, **kwds):
+class GlanceClient(Client):
+    def __init__(self, version, endpoint, token, cacert=None, *args, **kwds):
         Client.__init__(self, *args, **kwds)
         if has_openstack:
-            self.client = glanceclient.Client(version, endpoint=endpoint, token=token)
+            self.client = glanceclient.Client(version, 
+                endpoint=endpoint, 
+                token=token,
+                cacert=cacert
+            )
 
     @require_enabled
     def __getattr__(self, name):
@@ -178,9 +178,9 @@ class OpenStackClient:
         url_parsed = urlparse.urlparse(self.keystone.url)
         hostname = url_parsed.netloc.split(':')[0]
         token = self.keystone.client.tokens.authenticate(username=self.keystone.username, password=self.keystone.password, tenant_name=self.keystone.tenant)
-        #self.glance = GlanceClient(*args, **kwds)
+        glance_endpoint = self.keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL')
         
-        self.glanceclient = GlanceClientNew('1', endpoint='http://%s:9292' % hostname, token=token.id, **kwds)
+        self.glanceclient = GlanceClient('1', endpoint=glance_endpoint, token=token.id, **kwds)
         self.nova = NovaClient(*args, **kwds)
         # self.nova_db = NovaDB(*args, **kwds)
         self.quantum = QuantumClient(*args, **kwds)