]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Adding common base class for Rackspace Resource providers
authorVijendar Komalla <vijendar.komalla@RACKSPACE.COM>
Thu, 20 Jun 2013 17:09:02 +0000 (12:09 -0500)
committerVijendar Komalla <vijendar.komalla@RACKSPACE.COM>
Fri, 21 Jun 2013 19:18:13 +0000 (14:18 -0500)
Change-Id: If7d15e01c53fb6db4bdee5759b0ef4f087640c58

heat/engine/resources/rackspace/__init__.py [new file with mode: 0644]
heat/engine/resources/rackspace/rackspace_resource.py [new file with mode: 0644]

diff --git a/heat/engine/resources/rackspace/__init__.py b/heat/engine/resources/rackspace/__init__.py
new file mode 100644 (file)
index 0000000..9fcc287
--- /dev/null
@@ -0,0 +1,4 @@
+# pyrax client library is required to work with Rackspace cloud resources,
+# such as rackspace cloud database, rackspace cloud servers etc...
+# If pyrax client library is not installed, then heat-engine would not register
+# the rackspace cloud resource providers.
diff --git a/heat/engine/resources/rackspace/rackspace_resource.py b/heat/engine/resources/rackspace/rackspace_resource.py
new file mode 100644 (file)
index 0000000..0b98a22
--- /dev/null
@@ -0,0 +1,107 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+PYRAX_INSTALLED = True
+try:
+    import pyrax
+except ImportError:
+    PYRAX_INSTALLED = False
+
+from heat.engine import resource
+from heat.openstack.common import log as logging
+
+logger = logging.getLogger(__name__)
+
+
+class RackspaceResource(resource.Resource):
+    '''
+    Common base class for Rackspace Resource Providers
+    '''
+    properties_schema = {}
+
+    def __init__(self, name, json_snippet, stack):
+        super(RackspaceResource, self).__init__(name, json_snippet, stack)
+        if PYRAX_INSTALLED:
+            self.pyrax = pyrax
+        self._cloud_db = None
+        self._cloud_dns = None
+        self._cloud_lb = None
+        self._cloud_server = None
+        self._cloud_nw = None
+        self._cloud_blockstore = None
+        self._authenticated = False
+
+    def cloud_db(self):
+        '''Rackspace cloud database client.'''
+        if not self._cloud_db:
+            self.__authenticate()
+            self._cloud_db = self.pyrax.cloud_databases
+
+        return self._cloud_db
+
+    def cloud_lb(self):
+        '''Rackspace cloud loadbalancer client.'''
+        if not self._cloud_lb:
+            self.__authenticate()
+            self._cloud_lb = self.pyrax.cloud_loadbalancers
+
+        return self._cloud_lb
+
+    def cloud_dns(self):
+        '''Rackspace cloud dns client.'''
+        if not self._cloud_dns:
+            self.__authenticate()
+            self._cloud_dns = self.pyrax.cloud_dns
+
+        return self._cloud_dns
+
+    def nova(self):
+        '''Rackspace cloudservers client.'''
+        if not self._cloud_server:
+            self.__authenticate()
+            self._cloud_server = self.pyrax.cloudservers
+
+        return self._cloud_server
+
+    def cinder(self):
+        '''Rackspace cinder client.'''
+        if not self._cloud_blockstore:
+            self.__authenticate()
+            self._cloud_blockstore = self.pyrax.cloud_blockstorage
+
+        return self._cloud_blockstore
+
+    def quantum(self):
+        '''Rackspace quantum client.'''
+        if not self._cloud_nw:
+            self.__authenticate()
+            self._cloud_nw = self.pyrax.cloud_networks
+
+        return self._cloud_nw
+
+    def __authenticate(self):
+        # current implemenation shown below authenticates using
+        # username and password. Need make it work with auth-token
+        if not self._authenticated:
+            pyrax.set_setting("identity_type", "keystone")
+            pyrax.set_setting("auth_endpoint", self.context.auth_url)
+            pyrax.set_setting("tenant_id", self.context.tenant)
+            logger.info("Authenticating with username:%s" %
+                        self.context.username)
+            pyrax.set_credentials(self.context.username,
+                                  password=self.context.password)
+            logger.info("User %s authenticated successfully."
+                        % self.context.username)
+            self._authenticated = True