libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1444658 - in /libcloud/branches/0.12.x: ./ libcloud/compute/drivers/ libcloud/test/compute/ libcloud/test/compute/fixtures/opennebula_3_8/
Date Mon, 11 Feb 2013 05:27:58 GMT
Author: tomaz
Date: Mon Feb 11 05:27:57 2013
New Revision: 1444658

URL: http://svn.apache.org/r1444658
Log:
Backport changes from trunk.

Added:
    libcloud/branches/0.12.x/libcloud/test/compute/fixtures/opennebula_3_8/
      - copied from r1444657, libcloud/trunk/libcloud/test/compute/fixtures/opennebula_3_8/
    libcloud/branches/0.12.x/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_collection.xml
      - copied unchanged from r1444657, libcloud/trunk/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_collection.xml
    libcloud/branches/0.12.x/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_large.xml
      - copied unchanged from r1444657, libcloud/trunk/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_large.xml
    libcloud/branches/0.12.x/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_medium.xml
      - copied unchanged from r1444657, libcloud/trunk/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_medium.xml
    libcloud/branches/0.12.x/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_small.xml
      - copied unchanged from r1444657, libcloud/trunk/libcloud/test/compute/fixtures/opennebula_3_8/instance_type_small.xml
Modified:
    libcloud/branches/0.12.x/   (props changed)
    libcloud/branches/0.12.x/CHANGES
    libcloud/branches/0.12.x/libcloud/compute/drivers/opennebula.py
    libcloud/branches/0.12.x/libcloud/test/compute/test_opennebula.py

Propchange: libcloud/branches/0.12.x/
------------------------------------------------------------------------------
  Merged /libcloud/trunk:r1444081-1444657

Modified: libcloud/branches/0.12.x/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/CHANGES?rev=1444658&r1=1444657&r2=1444658&view=diff
==============================================================================
--- libcloud/branches/0.12.x/CHANGES (original)
+++ libcloud/branches/0.12.x/CHANGES Mon Feb 11 05:27:57 2013
@@ -153,6 +153,9 @@ Changes with Apache Libcloud 0.12.0:
      driver by providing ex_image_ids argument. (LIBCLOUD-294)
      [Chris Psaltis, Joseph Hall]
 
+   - Add support for OpenNebula 3.8. (LIBCLOUD-295)
+     [Guillaume ZITTA]
+
   *) Storage
 
     - Add a new local storage driver.

Modified: libcloud/branches/0.12.x/libcloud/compute/drivers/opennebula.py
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/compute/drivers/opennebula.py?rev=1444658&r1=1444657&r2=1444658&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/compute/drivers/opennebula.py (original)
+++ libcloud/branches/0.12.x/libcloud/compute/drivers/opennebula.py Mon Feb 11 05:27:57 2013
@@ -46,11 +46,13 @@ __all__ = [
     'OpenNebula_1_4_NodeDriver',
     'OpenNebula_2_0_NodeDriver',
     'OpenNebula_3_0_NodeDriver',
-    'OpenNebula_3_2_NodeDriver']
+    'OpenNebula_3_2_NodeDriver',
+    'OpenNebula_3_8_NodeDriver']
 
 API_HOST = ''
 API_PORT = (4567, 443)
 API_SECURE = True
+API_PLAIN_AUTH = False
 DEFAULT_API_VERSION = '3.2'
 
 
@@ -146,13 +148,20 @@ class OpenNebulaResponse(XmlResponse):
 class OpenNebulaConnection(ConnectionUserAndKey):
     """
     Connection class for the OpenNebula.org driver.
+    with plain_auth support
     """
 
     host = API_HOST
     port = API_PORT
     secure = API_SECURE
+    plain_auth = API_PLAIN_AUTH
     responseCls = OpenNebulaResponse
 
+    def __init__(self, *args, **kwargs):
+        if 'plain_auth' in kwargs:
+            self.plain_auth = kwargs.pop('plain_auth')
+        super(OpenNebulaConnection, self).__init__(*args, **kwargs)
+
     def add_default_headers(self, headers):
         """
         Add headers required by the OpenNebula.org OCCI interface.
@@ -166,10 +175,13 @@ class OpenNebulaConnection(ConnectionUse
         @rtype:  C{dict}
         @return: Dictionary containing updated headers.
         """
-        pass_sha1 = hashlib.sha1(b(self.key)).hexdigest()
+        if self.plain_auth:
+            passwd = self.key
+        else:
+            passwd = hashlib.sha1(b(self.key)).hexdigest()
         headers['Authorization'] =\
             ('Basic %s' % b64encode(b('%s:%s' % (self.user_id,
-                                                 pass_sha1))).decode('utf-8'))
+                                                 passwd))).decode('utf-8'))
         return headers
 
 
@@ -289,6 +301,12 @@ class OpenNebulaNodeDriver(NodeDriver):
                 cls = OpenNebula_3_0_NodeDriver
             elif api_version in ['3.2']:
                 cls = OpenNebula_3_2_NodeDriver
+            elif api_version in ['3.8']:
+                cls = OpenNebula_3_8_NodeDriver
+                if 'plain_auth' not in kwargs:
+                    kwargs['plain_auth'] = cls.plain_auth
+                else:
+                    cls.plain_auth = kwargs['plain_auth']
             else:
                 raise NotImplementedError(
                     "No OpenNebulaNodeDriver found for API version %s" %
@@ -1019,22 +1037,86 @@ class OpenNebula_3_2_NodeDriver(OpenNebu
         @rtype:  C{list} of L{OpenNebulaNodeSize}
         """
         sizes = []
-        ids = 1
+        size_id = 1
+
+        attributes = [('name', str, None), ('ram', int, 'MEMORY'),
+                      ('cpu', float, None), ('vcpu', float, None),
+                      ('disk', str, None), ('bandwidth', float, None),
+                      ('price', float, None)]
+
         for element in object.findall('INSTANCE_TYPE'):
-            sizes.append(OpenNebulaNodeSize(id=ids,
-                         name=element.findtext('NAME'),
-                         ram=int(element.findtext('MEMORY'))
-                             if element.findtext('MEMORY', None) else None,
-                         cpu=float(element.findtext('CPU'))
-                             if element.findtext('CPU', None) else None,
-                         vcpu=int(element.findtext('VCPU'))
-                             if element.findtext('VCPU', None) else None,
-                         disk=element.findtext('DISK', None),
-                         bandwidth=float(element.findtext('BANDWIDTH'))
-                             if element.findtext('BANDWIDTH', None) else None,
-                         price=float(element.findtext('PRICE'))
-                             if element.findtext('PRICE', None) else None,
-                         driver=self))
-            ids += 1
+            size_kwargs = {'id': size_id, 'driver': self}
+            values = self._get_attributes_values(attributes=attributes,
+                                                 element=element)
+            size_kwargs.update(values)
+
+            size = OpenNebulaNodeSize(**size_kwargs)
+            sizes.append(size)
+            size_id += 1
 
         return sizes
+
+    def _get_attributes_values(self, attributes, element):
+        values = {}
+
+        for attribute_name, attribute_type, alias in attributes:
+                key = alias if alias else attribute_name.upper()
+                value = element.findtext(key)
+
+                if value is not None:
+                    value = attribute_type(value)
+
+                values[attribute_name] = value
+
+        return values
+
+
+class OpenNebula_3_8_NodeDriver(OpenNebula_3_2_NodeDriver):
+    """
+    OpenNebula.org node driver for OpenNebula.org v3.8.
+    """
+
+    plain_auth = API_PLAIN_AUTH
+
+    def _to_sizes(self, object):
+        """
+        Request a list of instance types and convert that list to a list of
+        OpenNebulaNodeSize objects.
+
+        Request a list of instance types from the OpenNebula web interface,
+        and issue a request to convert each XML object representation of an
+        instance type to an OpenNebulaNodeSize object.
+
+        @return: List of instance types.
+        @rtype:  C{list} of L{OpenNebulaNodeSize}
+        """
+        sizes = []
+        size_id = 1
+
+        attributes = [('name', str, None), ('ram', int, 'MEMORY'),
+                      ('cpu', float, None), ('vcpu', float, None),
+                      ('disk', str, None), ('bandwidth', float, None),
+                      ('price', float, None)]
+
+        for element in object.findall('INSTANCE_TYPE'):
+            element = self.connection.request(
+                ('/instance_type/%s') % (element.attrib['name'])).object
+
+            size_kwargs = {'id': size_id, 'driver': self}
+            values = self._get_attributes_values(attributes=attributes,
+                                                 element=element)
+            size_kwargs.update(values)
+
+            size = OpenNebulaNodeSize(**size_kwargs)
+            sizes.append(size)
+            size_id += 1
+        return sizes
+
+    def _ex_connection_class_kwargs(self):
+        """
+        Set plain_auth as an extra L{OpenNebulaConnection_3_8} argument
+
+        @return: C{dict} of L{OpenNebulaConnection_3_8} input arguments
+        """
+
+        return {'plain_auth': self.plain_auth}

Modified: libcloud/branches/0.12.x/libcloud/test/compute/test_opennebula.py
URL: http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/test/compute/test_opennebula.py?rev=1444658&r1=1444657&r2=1444658&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/test/compute/test_opennebula.py (original)
+++ libcloud/branches/0.12.x/libcloud/test/compute/test_opennebula.py Mon Feb 11 05:27:57
2013
@@ -631,6 +631,56 @@ class OpenNebula_3_2_Tests(unittest.Test
         self.assertEqual(size.bandwidth, None)
         self.assertEqual(size.price, None)
 
+class OpenNebula_3_8_Tests(unittest.TestCase, OpenNebulaCaseMixin):
+    """
+    OpenNebula.org test suite for OpenNebula v3.8.
+    """
+
+    def setUp(self):
+        """
+        Setup test environment.
+        """
+        OpenNebulaNodeDriver.connectionCls.conn_classes = (
+            OpenNebula_3_8_MockHttp, OpenNebula_3_8_MockHttp)
+        self.driver = OpenNebulaNodeDriver(*OPENNEBULA_PARAMS + ('3.8',))
+
+    def test_list_sizes(self):
+        """
+        Test ex_list_networks functionality.
+        """
+        sizes = self.driver.list_sizes()
+
+        self.assertEqual(len(sizes), 3)
+        size = sizes[0]
+        self.assertEqual(size.id, '1')
+        self.assertEqual(size.name, 'small')
+        self.assertEqual(size.ram, 1024)
+        self.assertEqual(size.cpu, 1)
+        self.assertEqual(size.vcpu, None)
+        self.assertEqual(size.disk, None)
+        self.assertEqual(size.bandwidth, None)
+        self.assertEqual(size.price, None)
+
+        size = sizes[1]
+        self.assertEqual(size.id, '2')
+        self.assertEqual(size.name, 'medium')
+        self.assertEqual(size.ram, 4096)
+        self.assertEqual(size.cpu, 4)
+        self.assertEqual(size.vcpu, None)
+        self.assertEqual(size.disk, None)
+        self.assertEqual(size.bandwidth, None)
+        self.assertEqual(size.price, None)
+
+        size = sizes[2]
+        self.assertEqual(size.id, '3')
+        self.assertEqual(size.name, 'large')
+        self.assertEqual(size.ram, 8192)
+        self.assertEqual(size.cpu, 8)
+        self.assertEqual(size.vcpu, None)
+        self.assertEqual(size.disk, None)
+        self.assertEqual(size.bandwidth, None)
+        self.assertEqual(size.price, None)
+
 
 class OpenNebula_1_4_MockHttp(MockHttp):
     """
@@ -1019,5 +1069,45 @@ class OpenNebula_3_2_MockHttp(OpenNebula
             body = self.fixtures_3_2.load('instance_type_collection.xml')
             return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+
+class OpenNebula_3_8_MockHttp(OpenNebula_3_2_MockHttp):
+    """
+    Mock HTTP server for testing v3.8 of the OpenNebula.org compute driver.
+    """
+
+    fixtures_3_8 = ComputeFileFixtures('opennebula_3_8')
+
+    def _instance_type(self, method, url, body, headers):
+        """
+        Instance type pool.
+        """
+        if method == 'GET':
+            body = self.fixtures_3_8.load('instance_type_collection.xml')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _instance_type_small(self, method, url, body, headers):
+        """
+        Small instance type.
+        """
+        if method == 'GET':
+            body = self.fixtures_3_8.load('instance_type_small.xml')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _instance_type_medium(self, method, url, body, headers):
+        """
+        Medium instance type pool.
+        """
+        if method == 'GET':
+            body = self.fixtures_3_8.load('instance_type_medium.xml')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _instance_type_large(self, method, url, body, headers):
+        """
+        Large instance type pool.
+        """
+        if method == 'GET':
+            body = self.fixtures_3_8.load('instance_type_large.xml')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 if __name__ == '__main__':
     sys.exit(unittest.main())



Mime
View raw message