libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] git commit: LIBCLOUD-516: Add list_size() support into Eucalyptus for cluster versions >= 3.3.0. In this version Eucalyptus introduced the DescribeInstanceTypes call which is specific to EUCA and is not AWS compatible. This call requires a differen
Date Wed, 12 Feb 2014 15:30:24 GMT
Updated Branches:
  refs/heads/trunk 711d8e36a -> 77fb3491e


LIBCLOUD-516: Add list_size() support into Eucalyptus for cluster versions >= 3.3.0. In
this version Eucalyptus introduced the DescribeInstanceTypes call which is specific to EUCA
and is not AWS compatible. This call requires a different XML namespace.

Closes #249.

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/773cd3d1
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/773cd3d1
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/773cd3d1

Branch: refs/heads/trunk
Commit: 773cd3d1541ae364eb9d88f7590c1e4b56579508
Parents: 711d8e3
Author: Chris DeRamus <chris@divvycloud.com>
Authored: Sun Feb 9 15:57:56 2014 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Wed Feb 12 16:27:09 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py                 | 56 +++++++++++++++++++-
 .../fixtures/ec2/describe_instance_types.xml    |  1 +
 libcloud/test/compute/test_ec2.py               | 15 +++++-
 3 files changed, 70 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/773cd3d1/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index cade2ec..6222657 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -44,6 +44,8 @@ __all__ = [
     'API_VERSION',
     'NAMESPACE',
     'INSTANCE_TYPES',
+    'DEFAULT_EUCA_API_VERSION',
+    'EUCA_NAMESPACE',
 
     'EC2NodeDriver',
     'BaseEC2NodeDriver',
@@ -64,6 +66,10 @@ __all__ = [
 API_VERSION = '2013-10-15'
 NAMESPACE = 'http://ec2.amazonaws.com/doc/%s/' % (API_VERSION)
 
+# Eucalyptus Constants
+DEFAULT_EUCA_API_VERSION = '3.3.0'
+EUCA_NAMESPACE = 'http://msgs.eucalyptus.com/%s' % (DEFAULT_EUCA_API_VERSION)
+
 """
 Sizes must be hardcoded, because Amazon doesn't provide an API to fetch them.
 From http://aws.amazon.com/ec2/instance-types/
@@ -3875,22 +3881,70 @@ class EucNodeDriver(BaseEC2NodeDriver):
     connectionCls = EucConnection
 
     def __init__(self, key, secret=None, secure=True, host=None,
-                 path=None, port=None):
+                 path=None, port=None, api_version=DEFAULT_EUCA_API_VERSION):
         """
         @inherits: :class:`EC2NodeDriver.__init__`
 
         :param    path: The host where the API can be reached.
         :type     path: ``str``
+
+        :param    api_version: The API version to extend support for
+                               Eucalyptus proprietary API calls
+        :type     api_version: ``str``
         """
         super(EucNodeDriver, self).__init__(key, secret, secure, host, port)
+
         if path is None:
             path = '/services/Eucalyptus'
+
         self.path = path
+        self.EUCA_NAMESPACE = 'http://msgs.eucalyptus.com/%s' % (api_version)
 
     def list_locations(self):
         raise NotImplementedError(
             'list_locations not implemented for this driver')
 
+    def _to_sizes(self, response):
+        return [self._to_size(el) for el in response.findall(
+            fixxpath(xpath='instanceTypeDetails/item',
+                     namespace=self.EUCA_NAMESPACE))]
+
+    def _to_size(self, el):
+        name = findtext(element=el,
+                        xpath='name',
+                        namespace=self.EUCA_NAMESPACE)
+        cpu = findtext(element=el,
+                       xpath='cpu',
+                       namespace=self.EUCA_NAMESPACE)
+        disk = findtext(element=el,
+                        xpath='disk',
+                        namespace=self.EUCA_NAMESPACE)
+        memory = findtext(element=el,
+                          xpath='memory',
+                          namespace=self.EUCA_NAMESPACE)
+
+        return NodeSize(id=name,
+                        name=name,
+                        ram=int(memory),
+                        disk=int(disk),
+                        bandwidth=None,
+                        price=None,
+                        driver=EucNodeDriver,
+                        extra={
+                            'cpu': int(cpu)
+                        })
+
+    def list_sizes(self):
+        """
+        List available instance flavors/sizes
+
+        :rtype: ``list`` of :class:`NodeSize`
+        """
+        params = {'Action': 'DescribeInstanceTypes'}
+        response = self.connection.request(self.path, params=params).object
+
+        return self._to_sizes(response)
+
     def _add_instance_filter(self, params, node):
         """
         Eucalyptus driver doesn't support filtering on instance id so this is a

http://git-wip-us.apache.org/repos/asf/libcloud/blob/773cd3d1/libcloud/test/compute/fixtures/ec2/describe_instance_types.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/describe_instance_types.xml b/libcloud/test/compute/fixtures/ec2/describe_instance_types.xml
new file mode 100644
index 0000000..3fff98b
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ec2/describe_instance_types.xml
@@ -0,0 +1 @@
+<euca:DescribeInstanceTypesResponseType xmlns:euca="http://msgs.eucalyptus.com/3.4.1"><euca:VmTypeMessage><euca:_return>true</euca:_return><euca:_services/><euca:_disabledServices/><euca:_notreadyServices/><euca:_stoppedServices/></euca:VmTypeMessage><euca:instanceTypeDetails><euca:item><euca:name>m1.small</euca:name><euca:cpu>1</euca:cpu><euca:disk>5</euca:disk><euca:memory>256</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>t1.micro</euca:name><euca:cpu>1</euca:cpu><euca:disk>5</euca:disk><euca:memory>256</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>m1.medium</euca:name><euca:cpu>1</euca:cpu><euca:disk>10</euca:disk><euca:memory>512</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>c1.medium</euca:name><euca:cpu>2</euca:cpu><euca:disk>10</euca:disk><euca:memory>512</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>m1.large</
 euca:name><euca:cpu>1</euca:cpu><euca:disk>10</euca:disk><euca:memory>1024</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>c1.xlarge</euca:name><euca:cpu>2</euca:cpu><euca:disk>10</euca:disk><euca:memory>1024</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>m1.xlarge</euca:name><euca:cpu>1</euca:cpu><euca:disk>10</euca:disk><euca:memory>2048</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>m2.xlarge</euca:name><euca:cpu>2</euca:cpu><euca:disk>10</euca:disk><euca:memory>2048</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>m3.xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>15</euca:disk><euca:memory>2048</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>m2.2xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>30</euca:disk><euca:memory>4096</euca:memory><euca:availability/><euca:ephemeralD
 isk/></euca:item><euca:item><euca:name>m3.2xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>30</euca:disk><euca:memory>4096</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>cc1.4xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>60</euca:disk><euca:memory>3072</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>m2.4xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>60</euca:disk><euca:memory>4096</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>cc2.8xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>120</euca:disk><euca:memory>6144</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>hi1.4xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>120</euca:disk><euca:memory>6144</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>cg1.4xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>200</euca:disk><
 euca:memory>12288</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>cr1.8xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>240</euca:disk><euca:memory>16384</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item><euca:item><euca:name>hs1.8xlarge</euca:name><euca:cpu>16</euca:cpu><euca:disk>24000</euca:disk><euca:memory>119808</euca:memory><euca:availability/><euca:ephemeralDisk/></euca:item></euca:instanceTypeDetails></euca:DescribeInstanceTypesResponseType>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/773cd3d1/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index ceacdbd..63f15aa 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -1378,6 +1378,11 @@ class EucMockHttp(EC2MockHttp):
                                         headers):
         return self._CreateTags(method, url, body, headers)
 
+    def _services_Eucalyptus_DescribeInstanceTypes(self, method, url, body,
+                                                   headers):
+        body = self.fixtures.load('describe_instance_types.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 
 class NimbusTests(EC2Tests):
 
@@ -1444,7 +1449,7 @@ class EucTests(LibcloudTestCase, TestCaseMixin):
         EC2MockHttp.use_param = 'Action'
         EC2MockHttp.type = None
         self.driver = EucNodeDriver(key=EC2_PARAMS[0], secret=EC2_PARAMS[1],
-                                    host='some.eucalyptus.com')
+                                    host='some.eucalyptus.com', api_version='3.4.1')
 
     def test_list_locations_response(self):
         try:
@@ -1457,6 +1462,14 @@ class EucTests(LibcloudTestCase, TestCaseMixin):
     def test_list_location(self):
         pass
 
+    def test_list_sizes(self):
+        sizes = self.driver.list_sizes()
+        ids = [s.id for s in sizes]
+        self.assertEqual(len(ids), 18)
+        self.assertTrue('t1.micro' in ids)
+        self.assertTrue('m1.medium' in ids)
+        self.assertTrue('m3.xlarge' in ids)
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message