Fix access to openstack if cinder is not present
[osm/SO.git] / rwcal / plugins / vala / rwcal_openstack / rift / rwcal / openstack / cinder / cinder_drv.py
index 76bc8fe..5bb5cc4 100644 (file)
@@ -18,6 +18,7 @@
 import logging
 from cinderclient import client as ciclient
 import cinderclient.exceptions as CinderException
+import keystoneauth1
 
 
 class CinderAPIVersionException(Exception):
@@ -29,12 +30,16 @@ class CinderAPIVersionException(Exception):
         return self.__repr__()
         
     def __repr__(self):
-        msg = "{} : Following Exception(s) have occured during Neutron API discovery".format(self.__class__)
+        msg = "{} : Following Exception(s) have occured during Cinder API discovery".format(self.__class__)
         for n,e in enumerate(self.errors):
             msg += "\n"
             msg += " {}:  {}".format(n, str(e))
         return msg
 
+class CinderEndpointException(Exception):
+    "Cinder Endpoint is absent"
+    pass
+
 class CinderDriver(object):
     """
     CinderDriver Class for image management
@@ -89,6 +94,12 @@ class CinderDriver(object):
         else:
             raise CinderAPIVersionException(errors)
 
+        try:
+            self._ci_drv.client.get_endpoint()
+        except keystoneauth1.exceptions.catalog.EndpointNotFound:
+            self.log.info("Cinder endpoint not found")
+            raise CinderEndpointException()
+
     @property
     def cinder_endpoint(self):
         return self._ci_drv.client.get_endpoint()