You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/08/21 18:35:53 UTC
git commit: Modify EC2 driver create_node method and make extension
argument for assigning a node to a security group consistent with the
OpenStack implementation.
Updated Branches:
refs/heads/trunk 06521a0a5 -> f62392572
Modify EC2 driver create_node method and make extension argument for assigning
a node to a security group consistent with the OpenStack implementation.
Previously the argument was called ex_securitygroup, now it's called
ex_security_groups.
Part of LIBCLOUD-375.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f6239257
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f6239257
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f6239257
Branch: refs/heads/trunk
Commit: f6239257287cc1303dd3ee77f224f7d529d4066d
Parents: 06521a0
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Aug 21 18:33:08 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Aug 21 18:33:08 2013 +0200
----------------------------------------------------------------------
CHANGES | 7 ++++++
libcloud/compute/drivers/ec2.py | 26 +++++++++++++++-------
libcloud/test/compute/test_ec2.py | 40 +++++++++++++++++++++++++++++++++-
3 files changed, 64 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/f6239257/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 5f29488..041dae0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -59,6 +59,13 @@ Changes with Apache Libcloud in development
code when determining drive imaging success. (LIBCLOUD-363)
[Bob Thompson]
+ - Unify extension argument names for assigning a node to security groups
+ in EC2 ad OpenStack driver.
+ Argument in the EC2 driver has been renamed from ex_securitygroup to
+ ex_security_groups. For backward compatibility reasons, old argument
+ will continue to work for the unforeseeable future. (LIBCLOUD-375)
+ [Tomaz Muraus]
+
*) Storage
- Fix a regression with calling encode_container_name instead of
http://git-wip-us.apache.org/repos/asf/libcloud/blob/f6239257/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 627e788..3ddb3e5 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1325,9 +1325,9 @@ class BaseEC2NodeDriver(NodeDriver):
@keyword ex_maxcount: Maximum number of instances to launch
@type ex_maxcount: C{int}
- @keyword ex_securitygroup: Name of security group or a list of names
- for multiple security groups.
- @type ex_securitygroup: C{str} or C{list}
+ @keyword ex_security_groups: A list of namees of security groups to
+ assign to the node.
+ @type ex_security_groups: C{list}
@keyword ex_keyname: The name of the key pair
@type ex_keyname: C{str}
@@ -1354,12 +1354,22 @@ class BaseEC2NodeDriver(NodeDriver):
'InstanceType': size.id
}
- if 'ex_securitygroup' in kwargs:
- if not isinstance(kwargs['ex_securitygroup'], list):
- kwargs['ex_securitygroup'] = [kwargs['ex_securitygroup']]
- for sig in range(len(kwargs['ex_securitygroup'])):
+ if 'ex_security_groups' in kwargs and 'ex_securitygroup' in kwargs:
+ raise ValueError('You can only supply ex_security_groups or'
+ ' ex_securitygroup')
+
+ # ex_securitygroup is here for backward compatibility
+ ex_security_groups = kwargs.get('ex_security_groups', None)
+ ex_securitygroup = kwargs.get('ex_securitygroup', None)
+ security_groups = ex_security_groups or ex_securitygroup
+
+ if security_groups:
+ if not isinstance(security_groups, (tuple, list)):
+ security_groups = [security_groups]
+
+ for sig in range(len(security_groups)):
params['SecurityGroup.%d' % (sig + 1,)] =\
- kwargs['ex_securitygroup'][sig]
+ security_groups[sig]
if 'location' in kwargs:
availability_zone = getattr(kwargs['location'],
http://git-wip-us.apache.org/repos/asf/libcloud/blob/f6239257/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 6be7da3..0cc30f4 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -14,7 +14,8 @@
# limitations under the License.
import os
import sys
-import unittest
+
+from mock import Mock
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import parse_qsl
@@ -39,6 +40,7 @@ from libcloud.test import MockHttpTestCase, LibcloudTestCase
from libcloud.test.compute import TestCaseMixin
from libcloud.test.file_fixtures import ComputeFileFixtures
+from libcloud.test import unittest
from libcloud.test.secrets import EC2_PARAMS
@@ -455,6 +457,33 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
retValue = self.driver.detach_volume(vol)
self.assertTrue(retValue)
+ def test_create_node_ex_security_groups(self):
+ EC2MockHttp.type = 'ex_security_groups'
+
+ 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)
+
+ oldRequest = self.driver.connection.request
+
+ security_groups = ['group1', 'group2']
+
+ # Old, deprecated argument name
+ self.driver.create_node(name='foo', image=image, size=size,
+ ex_securitygroup=security_groups)
+
+ # New argument name
+ self.driver.create_node(name='foo', image=image, size=size,
+ ex_security_groups=security_groups)
+
+ # Test old and new arguments are mutally exclusive
+ self.assertRaises(ValueError, self.driver.create_node,
+ name='foo', image=image, size=size,
+ ex_securitygroup=security_groups,
+ ex_security_groups=security_groups)
+
class EC2USWest1Tests(EC2Tests):
region = 'us-west-1'
@@ -568,6 +597,15 @@ class EC2MockHttp(MockHttpTestCase):
body = self.fixtures.load('run_instances.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _ex_security_groups_RunInstances(self, method, url, body, headers):
+ params = dict(parse_qsl(url))
+
+ self.assertEqual(params['SecurityGroup.1'], 'group1')
+ self.assertEqual(params['SecurityGroup.1'], 'group1')
+
+ 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):
# Need to remove '/?'
url = url[2:]