Add update method of security group name and description

make it possible to edit the name and description of
common security groups, we can not rename the default.
nova patch : https://review.openstack.org/#/c/29490/

Fixes: bug #918393

Change-Id: I559f2fa09c1f205d3bbe7352fc169152e6b38586
This commit is contained in:
Zhenguo Niu 2013-05-22 16:28:34 +08:00 committed by Gerrit Code Review
parent def5df2760
commit 66a98966bf
6 changed files with 49 additions and 0 deletions

View File

@ -160,6 +160,7 @@ You'll find complete documentation on the shell by running
Add a source group rule to a security group.
secgroup-add-rule Add a rule to a security group.
secgroup-create Create a security group.
secgroup-update Update a security group.
secgroup-delete Delete a security group.
secgroup-delete-group-rule
Delete a source group rule from a security group.

View File

@ -1130,6 +1130,12 @@ class FakeHTTPClient(base_client.HTTPClient):
self.get_os_security_groups()[2]['security_groups'][0]}
return (202, {}, r)
def put_os_security_groups_1(self, body, **kw):
assert body.keys() == ['security_group']
fakes.assert_has_keys(body['security_group'],
required=['name', 'description'])
return (205, {}, body)
#
# Security Group Rules
#

View File

@ -45,6 +45,12 @@ class SecurityGroupsTest(utils.TestCase):
cs.assert_called('POST', '/os-security-groups')
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
def test_update_security_group(self):
sg = cs.security_groups.list()[0]
secgroup = cs.security_groups.update(sg, "update", "update")
cs.assert_called('PUT', '/os-security-groups/1')
self.assertTrue(isinstance(secgroup, security_groups.SecurityGroup))
def test_refresh_security_group(self):
sg = cs.security_groups.get(1)
sg2 = cs.security_groups.get(1)

View File

@ -1206,6 +1206,13 @@ class ShellTest(utils.TestCase):
{'name': 'test',
'description': 'FAKE_SECURITY_GROUP'}})
def test_security_group_update(self):
self.run_command('secgroup-update test te FAKE_SECURITY_GROUP')
self.assert_called('PUT', '/os-security-groups/1',
{'security_group':
{'name': 'te',
'description': 'FAKE_SECURITY_GROUP'}})
def test_security_group_list(self):
self.run_command('secgroup-list')
self.assert_called('GET', '/os-security-groups')

View File

@ -29,6 +29,9 @@ class SecurityGroup(base.Resource):
def delete(self):
self.manager.delete(self)
def update(self):
self.manager.update(self)
class SecurityGroupManager(base.ManagerWithFind):
resource_class = SecurityGroup
@ -44,6 +47,19 @@ class SecurityGroupManager(base.ManagerWithFind):
body = {"security_group": {"name": name, 'description': description}}
return self._create('/os-security-groups', body, 'security_group')
def update(self, group, name, description):
"""
Update a security group
:param group: The security group to delete (group or ID)
:param name: name for the security group to update
:param description: description for the security group to update
:rtype: the security group object
"""
body = {"security_group": {"name": name, 'description': description}}
return self._update('/os-security-groups/%s' % base.getid(group),
body, 'security_group')
def delete(self, group):
"""
Delete a security group

View File

@ -1978,6 +1978,19 @@ def do_secgroup_create(cs, args):
_print_secgroups([secgroup])
@utils.arg('secgroup',
metavar='<secgroup>',
help='ID or name of security group.')
@utils.arg('name', metavar='<name>', help='Name of security group.')
@utils.arg('description', metavar='<description>',
help='Description of security group.')
def do_secgroup_update(cs, args):
"""Update a security group."""
sg = _get_secgroup(cs, args.secgroup)
secgroup = cs.security_groups.update(sg, args.name, args.description)
_print_secgroups([secgroup])
@utils.arg('secgroup',
metavar='<secgroup>',
help='ID or name of security group.')