Skip to content

Commit

Permalink
Add update method of security group name and description
Browse files Browse the repository at this point in the history
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
  • Loading branch information
niuzhenguo authored and openstack-gerrit committed May 30, 2013
1 parent def5df2 commit 66a9896
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions novaclient/tests/v1_1/fakes.py
Expand Up @@ -1130,6 +1130,12 @@ def post_os_security_groups(self, body, **kw):
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
#
Expand Down
6 changes: 6 additions & 0 deletions novaclient/tests/v1_1/test_security_groups.py
Expand Up @@ -45,6 +45,12 @@ def test_create_security_group(self):
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)
Expand Down
7 changes: 7 additions & 0 deletions novaclient/tests/v1_1/test_shell.py
Expand Up @@ -1206,6 +1206,13 @@ def test_security_group_create(self):
{'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')
Expand Down
16 changes: 16 additions & 0 deletions novaclient/v1_1/security_groups.py
Expand Up @@ -29,6 +29,9 @@ def __str__(self):
def delete(self):
self.manager.delete(self)

def update(self):
self.manager.update(self)


class SecurityGroupManager(base.ManagerWithFind):
resource_class = SecurityGroup
Expand All @@ -44,6 +47,19 @@ def create(self, name, description):
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
Expand Down
13 changes: 13 additions & 0 deletions novaclient/v1_1/shell.py
Expand Up @@ -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.')
Expand Down

0 comments on commit 66a9896

Please sign in to comment.