Repository: libcloud Updated Branches: refs/heads/trunk d84f7f83b -> d7c8671cf
Ad ex_security_group_ids argument to the create_node method in the EC driver in order to be able to launch nodes with security groups on a VPC. Closes #373 Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/d7c8671c Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/d7c8671c Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/d7c8671c Branch: refs/heads/trunk Commit: d7c8671cf28eb02a5d73382fe5dd1ebeb95a4431 Parents: d84f7f8 Author: Itxaka Serrano <[email protected]> Authored: Sun Oct 12 01:05:42 2014 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Wed Nov 19 22:31:53 2014 +0800 ---------------------------------------------------------------------- CHANGES.rst | 5 +++++ libcloud/compute/drivers/ec2.py | 18 ++++++++++++++++++ libcloud/test/compute/test_ec2.py | 27 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/d7c8671c/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index 0c1975d..5a6f1be 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,6 +27,11 @@ Compute (GITHUB-389) [Loic Lambiel] +- Add ``ex_security_group_ids`` argument to the create_node method in the + EC2 driver. This way users can launch VPC nodes with security groups. + (GITHUB-373) + [Itxaka Serrano] + Changes with Apache Libcloud 0.16.0 ----------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/d7c8671c/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index 7018b68..2274c5e 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -2138,6 +2138,10 @@ class BaseEC2NodeDriver(NodeDriver): assign to the node. :type ex_security_groups: ``list`` + :keyword ex_security_group_ids: A list of ids of security groups to + assign to the node.[for VPC nodes only] + :type ex_security_group_ids: ``list`` + :keyword ex_metadata: Key/Value metadata to associate with a node :type ex_metadata: ``dict`` @@ -2190,6 +2194,20 @@ class BaseEC2NodeDriver(NodeDriver): params['SecurityGroup.%d' % (sig + 1,)] =\ security_groups[sig] + if 'ex_security_group_ids' in kwargs and 'ex_subnet' not in kwargs: + raise ValueError('You can only supply ex_security_group_ids' + ' combinated with ex_subnet') + + security_group_ids = kwargs.get('ex_security_group_ids', None) + + if security_group_ids: + if not isinstance(security_group_ids, (tuple, list)): + security_group_ids = [security_group_ids] + + for sig in range(len(security_group_ids)): + params['SecurityGroupId.%d' % (sig + 1,)] =\ + security_group_ids[sig] + if 'location' in kwargs: availability_zone = getattr(kwargs['location'], 'availability_zone', None) http://git-wip-us.apache.org/repos/asf/libcloud/blob/d7c8671c/libcloud/test/compute/test_ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index 8dfaac0..ce84912 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -34,6 +34,7 @@ from libcloud.compute.drivers.ec2 import OutscaleSASNodeDriver from libcloud.compute.drivers.ec2 import IdempotentParamError from libcloud.compute.drivers.ec2 import REGION_DETAILS from libcloud.compute.drivers.ec2 import ExEC2AvailabilityZone +from libcloud.compute.drivers.ec2 import EC2NetworkSubnet from libcloud.compute.base import Node, NodeImage, NodeSize, NodeLocation from libcloud.compute.base import StorageVolume, VolumeSnapshot from libcloud.compute.types import KeyPairDoesNotExistError @@ -877,6 +878,25 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin): ex_securitygroup=security_groups, ex_security_groups=security_groups) + def test_create_node_ex_security_group_ids(self): + EC2MockHttp.type = 'ex_security_group_ids' + + 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) + + subnet = EC2NetworkSubnet(12345, "test_subnet", "pending") + security_groups = ['sg-1aa11a1a', 'sg-2bb22b2b'] + + self.driver.create_node(name='foo', image=image, size=size, + ex_security_group_ids=security_groups, + ex_subnet=subnet) + self.assertRaises(ValueError, self.driver.create_node, + name='foo', image=image, size=size, + ex_security_group_ids=security_groups) + def test_ex_get_metadata_for_node(self): image = NodeImage(id='ami-be3adfd7', name=self.image_name, @@ -1195,6 +1215,13 @@ class EC2MockHttp(MockHttpTestCase): body = self.fixtures.load('run_instances.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _ex_security_group_ids_RunInstances(self, method, url, body, headers): + self.assertUrlContainsQueryParams(url, {'SecurityGroupId.1': 'sg-1aa11a1a'}) + self.assertUrlContainsQueryParams(url, {'SecurityGroupId.2': 'sg-2bb22b2b'}) + + 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): expected_params = { 'BlockDeviceMapping.1.DeviceName': '/dev/sda1',
