libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1392119 - in /libcloud/trunk/libcloud: compute/drivers/rackspace.py compute/drivers/rackspacenova.py compute/providers.py test/compute/test_rackspace.py test/compute/test_rackspacenova.py
Date Sun, 30 Sep 2012 21:50:53 GMT
Author: tomaz
Date: Sun Sep 30 21:50:52 2012
New Revision: 1392119

URL: http://svn.apache.org/viewvc?rev=1392119&view=rev
Log:
Move all of the Rackspace drivers and files in a single module, fix pep8 issues.

Removed:
    libcloud/trunk/libcloud/compute/drivers/rackspacenova.py
    libcloud/trunk/libcloud/test/compute/test_rackspacenova.py
Modified:
    libcloud/trunk/libcloud/compute/drivers/rackspace.py
    libcloud/trunk/libcloud/compute/providers.py
    libcloud/trunk/libcloud/test/compute/test_rackspace.py

Modified: libcloud/trunk/libcloud/compute/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/rackspace.py?rev=1392119&r1=1392118&r2=1392119&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/rackspace.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/rackspace.py Sun Sep 30 21:50:52 2012
@@ -17,18 +17,41 @@ Rackspace driver
 """
 from libcloud.compute.types import Provider, LibcloudError
 from libcloud.compute.base import NodeLocation
-from libcloud.compute.drivers.openstack import OpenStack_1_0_Connection,\
+from libcloud.compute.drivers.openstack import OpenStack_1_0_Connection, \
     OpenStack_1_0_NodeDriver, OpenStack_1_0_Response
+from libcloud.compute.drivers.openstack import OpenStack_1_1_Connection, \
+    OpenStack_1_1_NodeDriver
 
 from libcloud.common.rackspace import (
     AUTH_URL_US, AUTH_URL_UK)
 
 
+ENDPOINT_ARGS_MAP = {
+    'us': {
+        'dfw':  {'service_type': 'compute',
+                  'name': 'cloudServersOpenStack',
+                  'region': 'DFW'},
+        'ord':  {'service_type': 'compute',
+                  'name': 'cloudServersOpenStack',
+                  'region': 'ORD'}
+    },
+    'uk': {
+        'default':  {'service_type': 'compute',
+                     'name': 'cloudServersOpenStack',
+                     'region': 'LON'}
+    },
+    'beta': {
+        'dfw':  {'service_type': 'compute',
+                 'name': 'cloudServersPreprod',
+                 'region': 'DFW'}
+    }
+}
+
+
 class RackspaceFirstGenConnection(OpenStack_1_0_Connection):
     """
     Connection class for the Rackspace first-gen driver.
     """
-
     responseCls = OpenStack_1_0_Response
     auth_url = AUTH_URL_US
     XML_NAMESPACE = 'http://docs.rackspacecloud.com/servers/api/v1.0'
@@ -66,8 +89,9 @@ class RackspaceFirstGenNodeDriver(OpenSt
 
         self.region = region
 
-        super(RackspaceFirstGenNodeDriver, self).__init__(key=key, secret=secret,
-                       secure=secure, host=host, port=port, **kwargs)
+        super(RackspaceFirstGenNodeDriver, self).__init__(key=key,
+                      secret=secret, secure=secure, host=host,
+                      port=port, **kwargs)
 
     def list_locations(self):
         """
@@ -84,3 +108,56 @@ class RackspaceFirstGenNodeDriver(OpenSt
             locations = [NodeLocation(0, 'Rackspace UK London', 'UK', self)]
 
         return locations
+
+
+class RackspaceConnection(OpenStack_1_1_Connection):
+    """
+    Connection class for the Rackspace next-gen OpenStack base driver.
+    """
+    get_endpoint_args = {}
+
+    def get_endpoint(self):
+        if not self.get_endpoint_args:
+            raise LibcloudError(
+                'RackspaceConnection must have get_endpoint_args set')
+
+        # Only support auth 2.0_*
+        if '2.0' in self._auth_version:
+            ep = self.service_catalog.get_endpoint(**self.get_endpoint_args)
+        else:
+            raise LibcloudError(
+                'Auth version "%s" not supported' % (self._auth_version))
+
+        # It's possible to authenticate but the service catalog not have
+        # the correct endpoint for this driver, so we throw here.
+        if 'publicURL' in ep:
+            return ep['publicURL']
+        else:
+            raise LibcloudError('Could not find specified endpoint')
+
+
+class RackspaceNodeDriver(OpenStack_1_1_NodeDriver):
+    name = 'Rackspace Cloud'
+    website = 'http://www.rackspace.com'
+    connectionCls = RackspaceConnection
+    type = Provider.RACKSPACE
+    api_name = None
+
+    def __init__(self, key, secret=None, secure=True, host=None, port=None,
+                 region='us', datacenter='dfw', **kwargs):
+        if region not in ['us', 'uk']:
+            raise ValueError('Invalid region: %s' % (region))
+
+        if region == 'us' and datacenter not in ['dfw', 'ord']:
+            raise ValueError('Invalid datacenter: %s' % (datacenter))
+        elif region in ['uk']:
+            datacenter = 'default'
+
+        self.connectionCls.get_endpoint_args = \
+                ENDPOINT_ARGS_MAP[region][datacenter]
+
+        self.region = region
+        self.datacenter = datacenter
+
+        super(RackspaceNodeDriver, self).__init__(key=key, secret=secret,
+                       secure=secure, host=host, port=port, **kwargs)

Modified: libcloud/trunk/libcloud/compute/providers.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/providers.py?rev=1392119&r1=1392118&r2=1392119&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/providers.py (original)
+++ libcloud/trunk/libcloud/compute/providers.py Sun Sep 30 21:50:52 2012
@@ -64,7 +64,7 @@ DRIVERS = {
     Provider.GOGRID:
         ('libcloud.compute.drivers.gogrid', 'GoGridNodeDriver'),
     Provider.RACKSPACE:
-        ('libcloud.compute.drivers.rackspacenova', 'RackspaceNodeDriver'),
+        ('libcloud.compute.drivers.rackspace', 'RackspaceNodeDriver'),
     Provider.RACKSPACE_FIRST_GEN:
         ('libcloud.compute.drivers.rackspace', 'RackspaceFirstGenNodeDriver'),
     Provider.SLICEHOST:

Modified: libcloud/trunk/libcloud/test/compute/test_rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_rackspace.py?rev=1392119&r1=1392118&r2=1392119&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_rackspace.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_rackspace.py Sun Sep 30 21:50:52 2012
@@ -15,9 +15,16 @@
 import sys
 import unittest
 
+from libcloud.utils.py3 import method_type
+from libcloud.utils.py3 import httplib
 from libcloud.compute.drivers.rackspace import RackspaceFirstGenNodeDriver
+from libcloud.compute.drivers.rackspace import RackspaceNodeDriver
 from libcloud.test.compute.test_openstack import OpenStack_1_0_Tests
+from libcloud.test.compute.test_openstack import OpenStack_1_1_Tests, \
+                                                 OpenStack_1_1_MockHttp
+from libcloud.pricing import clear_pricing_data
 
+from libcloud.test.secrets import RACKSPACE_NOVA_PARAMS
 from libcloud.test.secrets import RACKSPACE_PARAMS
 
 
@@ -53,5 +60,143 @@ class RackspaceusFirstGenUkTests(OpenSta
             self.assertTrue(size.price > 0)
 
 
+class RackspaceNovaMockHttp(OpenStack_1_1_MockHttp):
+    def __init__(self, *args, **kwargs):
+        super(RackspaceNovaMockHttp, self).__init__(*args, **kwargs)
+
+        methods1 = OpenStack_1_1_MockHttp.__dict__
+
+        names1 = [m for m in methods1 if m.find('_v1_1') == 0]
+
+        for name in names1:
+            method = methods1[name]
+            new_name = name.replace('_v1_1_slug_', '_v2_1337_')
+            setattr(self, new_name, method_type(method, self,
+                RackspaceNovaMockHttp))
+
+
+class RackspaceNovaLonMockHttp(RackspaceNovaMockHttp):
+
+    def _v2_0_tokens(self, method, url, body, headers):
+        body = self.auth_fixtures.load('_v2_0__auth_lon.json')
+        return (httplib.OK, body, self.json_content_headers,
+                httplib.responses[httplib.OK])
+
+
+"""
+class RackspaceNovaBetaTests(OpenStack_1_1_Tests):
+
+    driver_klass = RackspaceNodeDriver
+    driver_type = RackspaceNodeDriver
+    driver_args = RACKSPACE_NOVA_PARAMS
+    driver_kwargs = {'region': 'beta', 'ex_force_auth_version': '2.0'}
+
+    @classmethod
+    def create_driver(self):
+        return self.driver_type(*self.driver_args, **self.driver_kwargs)
+
+    def setUp(self):
+        self.driver_klass.connectionCls.conn_classes = (RackspaceNovaMockHttp,
+                                                        RackspaceNovaMockHttp)
+        self.driver_klass.connectionCls.auth_url = \
+                "https://auth.api.example.com/v2.0/"
+        self.driver = self.create_driver()
+        # normally authentication happens lazily, but we force it here
+        self.driver.connection._populate_hosts_and_request_paths()
+        clear_pricing_data()
+        self.node = self.driver.list_nodes()[1]
+
+    def test_service_catalog(self):
+        self.assertEqual(
+            'https://preprod.dfw.servers.api.rackspacecloud.com/v2/1337',
+            self.driver.connection.get_endpoint())
+"""
+
+
+class RackspaceNovaDfwTests(OpenStack_1_1_Tests):
+
+    driver_klass = RackspaceNodeDriver
+    driver_type = RackspaceNodeDriver
+    driver_args = RACKSPACE_NOVA_PARAMS
+    driver_kwargs = {'region': 'us', 'datacenter': 'dfw',
+                     'ex_force_auth_version': '2.0'}
+
+    @classmethod
+    def create_driver(self):
+        return self.driver_type(*self.driver_args, **self.driver_kwargs)
+
+    def setUp(self):
+        self.driver_klass.connectionCls.conn_classes = (RackspaceNovaMockHttp,
+                                                        RackspaceNovaMockHttp)
+        self.driver_klass.connectionCls.auth_url = \
+                'https://auth.api.example.com/v2.0/'
+        self.driver = self.create_driver()
+        # normally authentication happens lazily, but we force it here
+        self.driver.connection._populate_hosts_and_request_paths()
+        clear_pricing_data()
+        self.node = self.driver.list_nodes()[1]
+
+    def test_service_catalog(self):
+        self.assertEqual(
+                'https://dfw.servers.api.rackspacecloud.com/v2/1337',
+                self.driver.connection.get_endpoint())
+
+
+class RackspaceNovaOrdTests(OpenStack_1_1_Tests):
+
+    driver_klass = RackspaceNodeDriver
+    driver_type = RackspaceNodeDriver
+    driver_args = RACKSPACE_NOVA_PARAMS
+    driver_kwargs = {'region': 'us', 'datacenter': 'ord',
+                     'ex_force_auth_version': '2.0'}
+
+    @classmethod
+    def create_driver(self):
+        return self.driver_type(*self.driver_args, **self.driver_kwargs)
+
+    def setUp(self):
+        self.driver_klass.connectionCls.conn_classes = (RackspaceNovaMockHttp,
+                                                        RackspaceNovaMockHttp)
+        self.driver_klass.connectionCls.auth_url = \
+                'https://auth.api.example.com/v2.0/'
+        self.driver = self.create_driver()
+        # normally authentication happens lazily, but we force it here
+        self.driver.connection._populate_hosts_and_request_paths()
+        clear_pricing_data()
+        self.node = self.driver.list_nodes()[1]
+
+    def test_service_catalog(self):
+        self.assertEqual('https://ord.servers.api.rackspacecloud.com/v2/1337',
+                         self.driver.connection.get_endpoint())
+
+
+class RackspaceNovaLonTests(OpenStack_1_1_Tests):
+
+    driver_klass = RackspaceNodeDriver
+    driver_type = RackspaceNodeDriver
+    driver_args = RACKSPACE_NOVA_PARAMS
+    driver_kwargs = {'region': 'uk', 'datacenter': 'ord',
+                     'ex_force_auth_version': '2.0'}
+
+    @classmethod
+    def create_driver(self):
+        return self.driver_type(*self.driver_args, **self.driver_kwargs)
+
+    def setUp(self):
+        self.driver_klass.connectionCls.conn_classes = \
+                (RackspaceNovaLonMockHttp, RackspaceNovaLonMockHttp)
+        self.driver_klass.connectionCls.auth_url = \
+                'https://lon.auth.api.example.com/v2.0/'
+        self.driver = self.create_driver()
+        # normally authentication happens lazily, but we force it here
+        self.driver.connection._populate_hosts_and_request_paths()
+        clear_pricing_data()
+        self.node = self.driver.list_nodes()[1]
+
+    def test_service_catalog(self):
+        self.assertEqual('https://lon.servers.api.rackspacecloud.com/v2/1337',
+                         self.driver.connection.get_endpoint())
+
+
 if __name__ == '__main__':
     sys.exit(unittest.main())



Mime
View raw message