libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1438350 - in /libcloud/trunk: CHANGES libcloud/compute/drivers/ec2.py libcloud/test/compute/test_ec2.py
Date Fri, 25 Jan 2013 06:54:12 GMT
Author: tomaz
Date: Fri Jan 25 06:54:11 2013
New Revision: 1438350

URL: http://svn.apache.org/viewvc?rev=1438350&view=rev
Log:
Allow user to pass 'ex_blockdevicemappings' kwarg to the EC2 driver
create_node method.

Contributed by Joe Miller, part of LIBCLOUD-282.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/compute/drivers/ec2.py
    libcloud/trunk/libcloud/test/compute/test_ec2.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1438350&r1=1438349&r2=1438350&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Fri Jan 25 06:54:11 2013
@@ -103,6 +103,10 @@ Changes with Apache Libcloud in developm
    - Add new driver for Abiquo provider - http://www.abiquo.com (LIBCLOUD-250).
      [Jaume Devesa]
 
+   - Allow user to pass 'ex_blockdevicemappings' kwarg to the EC2 driver
+     'create_node' method. (LIBCLOUD-282)
+     [Joe Miller, Tomaz Muraus]
+
   *) Storage
 
     - Add a new local storage driver.

Modified: libcloud/trunk/libcloud/compute/drivers/ec2.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/ec2.py?rev=1438350&r1=1438349&r2=1438350&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/ec2.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/ec2.py Fri Jan 25 06:54:11 2013
@@ -154,7 +154,7 @@ INSTANCE_TYPES = {
         'id': 'cr1.8xlarge',
         'name': 'High Memory Cluster Eight Extra Large',
         'ram': 244000,
-        'disk': 240, # 2 x 120 GB SSD
+        'disk': 240,
         'bandwidth': None
     },
     'hs1.8xlarge': {
@@ -1251,6 +1251,11 @@ class BaseEC2NodeDriver(NodeDriver):
 
         @keyword    ex_clienttoken: Unique identifier to ensure idempotency
         @type       ex_clienttoken: C{str}
+
+        @keyword    ex_blockdevicemappings: C{list} of C{dict} block device
+                    mappings. Example:
+                    [{'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'}]
+        @type       ex_blockdevicemappings: C{list} of C{dict}
         """
         image = kwargs["image"]
         size = kwargs["size"]
@@ -1288,6 +1293,13 @@ class BaseEC2NodeDriver(NodeDriver):
         if 'ex_clienttoken' in kwargs:
             params['ClientToken'] = kwargs['ex_clienttoken']
 
+        if 'ex_blockdevicemappings' in kwargs:
+            for index, mapping in enumerate(kwargs['ex_blockdevicemappings']):
+                params['BlockDeviceMapping.%d.DeviceName' % (index + 1)] = \
+                    mapping['DeviceName']
+                params['BlockDeviceMapping.%d.VirtualName' % (index + 1)] = \
+                    mapping['VirtualName']
+
         object = self.connection.request(self.path, params=params).object
         nodes = self._to_nodes(object, 'instancesSet/item')
 

Modified: libcloud/trunk/libcloud/test/compute/test_ec2.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_ec2.py?rev=1438350&r1=1438349&r2=1438350&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_ec2.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_ec2.py Fri Jan 25 06:54:11 2013
@@ -28,15 +28,22 @@ from libcloud.compute.drivers.ec2 import
 from libcloud.compute.drivers.ec2 import NimbusNodeDriver, EucNodeDriver
 from libcloud.compute.drivers.ec2 import IdempotentParamError
 from libcloud.compute.drivers.ec2 import REGION_DETAILS
+from libcloud.utils.py3 import urlparse
 from libcloud.compute.base import Node, NodeImage, NodeSize, NodeLocation
 from libcloud.compute.base import StorageVolume
 
-from libcloud.test import MockHttp, LibcloudTestCase
+from libcloud.test import MockHttpTestCase, LibcloudTestCase
 from libcloud.test.compute import TestCaseMixin
 from libcloud.test.file_fixtures import ComputeFileFixtures
 
 from libcloud.test.secrets import EC2_PARAMS
 
+try:
+    parse_qsl = urlparse.parse_qsl
+except AttributeError:
+    import cgi
+    parse_qsl = cgi.parse_qsl
+
 
 class BaseEC2Tests(LibcloudTestCase):
     def test_instantiate_driver_valid_datacenters(self):
@@ -191,6 +198,22 @@ class EC2Tests(LibcloudTestCase, TestCas
         ret = self.driver.ex_stop_node(node)
         self.assertTrue(ret)
 
+    def test_ex_create_node_with_ex_blockdevicemappings(self):
+        EC2MockHttp.type = 'create_ex_blockdevicemappings'
+
+        image = NodeImage(id='ami-be3adfd7',
+                          name=self.image_name,
+                          driver=self.driver)
+        size = NodeSize('m1.small', 'Small Instance', None, None, None, None,
+                        driver=self.driver)
+        mappings = [
+            {'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'},
+            {'DeviceName': '/dev/sdc', 'VirtualName': 'ephemeral1'}
+        ]
+        node = self.driver.create_node(name='foo', image=image, size=size,
+                                       ex_blockdevicemappings=mappings)
+        self.assertEqual(node.id, 'i-2ba64342')
+
     def test_destroy_node(self):
         node = Node('i-4382922a', None, None, None, None, self.driver)
         ret = self.driver.destroy_node(node)
@@ -442,7 +465,7 @@ class EC2SAEastOldStyleModelTests(EC2Old
     driver_klass = EC2SAEastNodeDriver
 
 
-class EC2MockHttp(MockHttp):
+class EC2MockHttp(MockHttpTestCase):
     fixtures = ComputeFileFixtures('ec2')
 
     def _DescribeInstances(self, method, url, body, headers):
@@ -485,6 +508,20 @@ class EC2MockHttp(MockHttp):
         body = self.fixtures.load('run_instances.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _create_ex_blockdevicemappings_RunInstances(self, method, url, body, headers):
+        parameters = dict(parse_qsl(url))
+        self.assertEqual(parameters['BlockDeviceMapping.1.DeviceName'],
+                         '/dev/sdb')
+        self.assertEqual(parameters['BlockDeviceMapping.1.VirtualName'],
+                         'ephemeral0')
+        self.assertEqual(parameters['BlockDeviceMapping.2.DeviceName'],
+                         '/dev/sdc')
+        self.assertEqual(parameters['BlockDeviceMapping.2.VirtualName'],
+                         'ephemeral1')
+
+        body = self.fixtures.load('run_instances.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _idempotent_RunInstances(self, method, url, body, headers):
         body = self.fixtures.load('run_instances_idem.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])



Mime
View raw message