libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/4] git commit: Issue LIBCLOUD-365: change ec2 ex_blockdevicemappings to support all possible key/values
Date Thu, 25 Jul 2013 07:21:24 GMT
Updated Branches:
  refs/heads/0.13.x ac7c6adb2 -> 87e49260b
  refs/heads/trunk bf162b725 -> 4cdf44748


Issue LIBCLOUD-365: change ec2 ex_blockdevicemappings to support all possible key/values

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/56379a3a
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/56379a3a
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/56379a3a

Branch: refs/heads/trunk
Commit: 56379a3a830776162f3ac5a5fa169e6f5b5e4203
Parents: bf162b7
Author: joe miller <joeym@joeym.net>
Authored: Sun Jul 21 07:48:23 2013 -0700
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Jul 25 08:53:54 2013 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py   | 18 ++++++++++++------
 libcloud/test/compute/test_ec2.py | 30 +++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/56379a3a/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index ea048df..c913b5f 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1291,7 +1291,8 @@ class BaseEC2NodeDriver(NodeDriver):
 
         @keyword    ex_blockdevicemappings: C{list} of C{dict} block device
                     mappings. Example:
-                    [{'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'}]
+                    [{'DeviceName': '/dev/sda1', 'Ebs.VolumeSize': 10},
+                     {'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'}]
         @type       ex_blockdevicemappings: C{list} of C{dict}
         """
         image = kwargs["image"]
@@ -1331,11 +1332,16 @@ class BaseEC2NodeDriver(NodeDriver):
             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']
+            if not isinstance(kwargs['ex_blockdevicemappings'], (list, tuple)):
+                raise AttributeError('ex_blockdevicemappings not list or tuple')
+
+            for idx, mapping in enumerate(kwargs['ex_blockdevicemappings'],
+                                          start=1):
+                if not isinstance(mapping, dict):
+                    raise AttributeError('mapping %s in ex_blockdevicemappings '
+                                         'not a dict' % mapping)
+                for k, v in mapping.items():
+                    params['BlockDeviceMapping.%d.%s' % (idx, k)] = str(v)
 
         object = self.connection.request(self.path, params=params).object
         nodes = self._to_nodes(object, 'instancesSet/item')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/56379a3a/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index feb517e..e62b721 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -206,6 +206,7 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         size = NodeSize('m1.small', 'Small Instance', None, None, None, None,
                         driver=self.driver)
         mappings = [
+            {'DeviceName': '/dev/sda1', 'Ebs.VolumeSize': 10},
             {'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'},
             {'DeviceName': '/dev/sdc', 'VirtualName': 'ephemeral1'}
         ]
@@ -213,6 +214,25 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
                                        ex_blockdevicemappings=mappings)
         self.assertEqual(node.id, 'i-2ba64342')
 
+    def test_ex_create_node_with_ex_blockdevicemappings_attribute_error(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 = 'this should be a list'
+        self.assertRaises(AttributeError, self.driver.create_node, name='foo',
+                                       image=image, size=size,
+                                       ex_blockdevicemappings=mappings)
+
+        mappings = ['this should be a dict']
+        self.assertRaises(AttributeError, self.driver.create_node, name='foo',
+                                       image=image, size=size,
+                                       ex_blockdevicemappings=mappings)
+
     def test_destroy_node(self):
         node = Node('i-4382922a', None, None, None, None, self.driver)
         ret = self.driver.destroy_node(node)
@@ -530,12 +550,16 @@ class EC2MockHttp(MockHttpTestCase):
     def _create_ex_blockdevicemappings_RunInstances(self, method, url, body, headers):
         parameters = dict(parse_qsl(url))
         self.assertEqual(parameters['BlockDeviceMapping.1.DeviceName'],
+                         '/dev/sda1')
+        self.assertEqual(parameters['BlockDeviceMapping.1.Ebs.VolumeSize'],
+                         '10')
+        self.assertEqual(parameters['BlockDeviceMapping.2.DeviceName'],
                          '/dev/sdb')
-        self.assertEqual(parameters['BlockDeviceMapping.1.VirtualName'],
+        self.assertEqual(parameters['BlockDeviceMapping.2.VirtualName'],
                          'ephemeral0')
-        self.assertEqual(parameters['BlockDeviceMapping.2.DeviceName'],
+        self.assertEqual(parameters['BlockDeviceMapping.3.DeviceName'],
                          '/dev/sdc')
-        self.assertEqual(parameters['BlockDeviceMapping.2.VirtualName'],
+        self.assertEqual(parameters['BlockDeviceMapping.3.VirtualName'],
                          'ephemeral1')
 
         body = self.fixtures.load('run_instances.xml')


Mime
View raw message