Updated Branches: refs/heads/trunk 2311fda18 -> adba6dee0
Issue LIBCLOUD-464: Add methods for deleting security groups to the EC2 driver. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/556bc918 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/556bc918 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/556bc918 Branch: refs/heads/trunk Commit: 556bc918d3fd45f3fa81dbbdff88a4ea1fe4b825 Parents: 2311fda Author: Chris DeRamus <[email protected]> Authored: Thu Dec 19 23:47:12 2013 -0500 Committer: Tomaz Muraus <[email protected]> Committed: Sun Dec 22 02:18:40 2013 +0100 ---------------------------------------------------------------------- libcloud/compute/drivers/ec2.py | 46 ++++++++++++++++++++ .../fixtures/ec2/delete_security_group.xml | 4 ++ libcloud/test/compute/test_ec2.py | 19 ++++++++ 3 files changed, 69 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/556bc918/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index 90fc864..5a60b9e 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -1343,6 +1343,52 @@ class BaseEC2NodeDriver(NodeDriver): 'group_id': group_id } + def ex_delete_security_group_by_id(self, group_id): + """ + Deletes a new Security Group using the group id. + + :param group_id: The ID of the security group + :type group_id: ``str`` + + :rtype: ``bool`` + """ + params = {'Action': 'DeleteSecurityGroup', 'GroupId': group_id} + + result = self.connection.request(self.path, params=params).object + element = findtext(element=result, xpath='return', + namespace=NAMESPACE) + + return element == 'true' + + def ex_delete_security_group_by_name(self, group_name): + """ + Deletes a new Security Group using the group name. + + :param group_name: The name of the security group + :type group_name: ``str`` + + :rtype: ``bool`` + """ + params = {'Action': 'DeleteSecurityGroup', 'GroupName': group_name} + + result = self.connection.request(self.path, params=params).object + element = findtext(element=result, xpath='return', + namespace=NAMESPACE) + + return element == 'true' + + def ex_delete_security_group(self, name): + """ + Wrapper method which calls ex_delete_security_group_by_name + + :param name: The name of the security group + :type name ``str`` + + :rtype: ``bool`` + """ + + return self.ex_destroy_security_group_by_name(name) + def ex_authorize_security_group(self, name, from_port, to_port, cidr_ip, protocol='tcp'): """ http://git-wip-us.apache.org/repos/asf/libcloud/blob/556bc918/libcloud/test/compute/fixtures/ec2/delete_security_group.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/ec2/delete_security_group.xml b/libcloud/test/compute/fixtures/ec2/delete_security_group.xml new file mode 100644 index 0000000..2dc4eec --- /dev/null +++ b/libcloud/test/compute/fixtures/ec2/delete_security_group.xml @@ -0,0 +1,4 @@ +<DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/"> + <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> + <return>true</return> +</DeleteSecurityGroupResponse> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/556bc918/libcloud/test/compute/test_ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index 1a843fd..70ec986 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -215,6 +215,21 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin): groups = self.driver.ex_list_security_groups() self.assertEqual(groups, ['WebServers', 'RangedPortsBySource']) + def test_ex_delete_security_group_by_id(self): + group_id = 'sg-443d0a12' + retValue = self.driver.ex_delete_security_group_by_id(group_id) + self.assertTrue(retValue) + + def text_ex_delete_security_group_by_name(self): + group_name = 'WebServers' + retValue = self.driver.ex_delete_security_group_by_name(group_name) + self.assertTrue(retValue) + + def text_ex_delete_security_group(self): + name = 'WebServers' + retValue = self.driver.ex_delete_security_group(name) + self.assertTrue(retValue) + def test_authorize_security_group(self): resp = self.driver.ex_authorize_security_group('TestGroup', '22', '22', '0.0.0.0/0') @@ -848,6 +863,10 @@ class EC2MockHttp(MockHttpTestCase): body = self.fixtures.load('describe_security_groups.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _DeleteSecurityGroup(self, method, url, body, headers): + body = self.fixtures.load('delete_security_group.xml') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _AuthorizeSecurityGroupIngress(self, method, url, body, headers): body = self.fixtures.load('authorize_security_group_ingress.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK])
