Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions libcloud/compute/drivers/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,52 @@ def ex_create_security_group(self, name, description):
'GroupDescription': description}
return self.connection.request(self.path, params=params).object

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'):
"""
Expand Down
4 changes: 4 additions & 0 deletions libcloud/test/compute/fixtures/ec2/delete_security_group.xml
Original file line number Diff line number Diff line change
@@ -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>
19 changes: 19 additions & 0 deletions libcloud/test/compute/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ def test_list_security_groups(self):
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')
Expand Down Expand Up @@ -809,6 +824,10 @@ def _DescribeSecurityGroups(self, method, url, body, headers):
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])
Expand Down