Merge "Add update method of security group name and description"
This commit is contained in:
commit
76d566b760
README.rst
novaclient
@ -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.
|
||||
|
@ -1160,6 +1160,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
|
||||
#
|
||||
|
@ -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)
|
||||
|
@ -1287,6 +1287,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')
|
||||
|
@ -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
|
||||
|
@ -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.')
|
||||
|
Loading…
x
Reference in New Issue
Block a user