Add update method of security group name and description
make it possible to edit the name and description of security groups. Fixes: bug #918393 Change-Id: I7b9dd3f9ad2f59aee1b37e06350ce8f5e3a40f64
This commit is contained in:
@@ -73,6 +73,31 @@ class DeleteSecurityGroup(quantumv20.DeleteCommand):
|
||||
allow_names = True
|
||||
|
||||
|
||||
class UpdateSecurityGroup(quantumv20.UpdateCommand):
|
||||
"""Update a given security group."""
|
||||
|
||||
log = logging.getLogger(__name__ + '.UpdateSecurityGroup')
|
||||
resource = 'security_group'
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
help='Name of security group')
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
help='description of security group')
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
body = {'security_group': {}}
|
||||
if parsed_args.name:
|
||||
body['security_group'].update(
|
||||
{'name': parsed_args.name})
|
||||
if parsed_args.description:
|
||||
body['security_group'].update(
|
||||
{'description': parsed_args.description})
|
||||
return body
|
||||
|
||||
|
||||
class ListSecurityGroupRule(quantumv20.ListCommand):
|
||||
"""List security group rules that belong to a given tenant."""
|
||||
|
||||
|
||||
@@ -150,6 +150,8 @@ COMMAND_V2 = {
|
||||
'quantumclient.quantum.v2_0.securitygroup.CreateSecurityGroup'),
|
||||
'security-group-delete': utils.import_class(
|
||||
'quantumclient.quantum.v2_0.securitygroup.DeleteSecurityGroup'),
|
||||
'security-group-update': utils.import_class(
|
||||
'quantumclient.quantum.v2_0.securitygroup.UpdateSecurityGroup'),
|
||||
'security-group-rule-list': utils.import_class(
|
||||
'quantumclient.quantum.v2_0.securitygroup.ListSecurityGroupRule'),
|
||||
'security-group-rule-show': utils.import_class(
|
||||
|
||||
@@ -470,6 +470,14 @@ class Client(object):
|
||||
"""
|
||||
return self.post(self.security_groups_path, body=body)
|
||||
|
||||
@APIParamsCall
|
||||
def update_security_group(self, security_group, body=None):
|
||||
"""
|
||||
Updates a security group
|
||||
"""
|
||||
return self.put(self.security_group_path %
|
||||
security_group, body=body)
|
||||
|
||||
@APIParamsCall
|
||||
def list_security_groups(self, retrieve_all=True, **_params):
|
||||
"""
|
||||
|
||||
@@ -118,6 +118,29 @@ class CLITestV20SecurityGroupsJSON(test_cli20.CLITestV20Base):
|
||||
args = [myid]
|
||||
self._test_delete_resource(resource, cmd, myid, args)
|
||||
|
||||
def test_update_security_group(self):
|
||||
"""Update security group: myid --name myname --description desc."""
|
||||
resource = 'security_group'
|
||||
cmd = securitygroup.UpdateSecurityGroup(
|
||||
test_cli20.MyApp(sys.stdout), None)
|
||||
self._test_update_resource(resource, cmd, 'myid',
|
||||
['myid', '--name', 'myname',
|
||||
'--description', 'mydescription'],
|
||||
{'name': 'myname',
|
||||
'description': 'mydescription'}
|
||||
)
|
||||
|
||||
def test_update_security_group_with_unicode(self):
|
||||
resource = 'security_group'
|
||||
cmd = securitygroup.UpdateSecurityGroup(
|
||||
test_cli20.MyApp(sys.stdout), None)
|
||||
self._test_update_resource(resource, cmd, 'myid',
|
||||
['myid', '--name', u'\u7f51\u7edc',
|
||||
'--description', u'\u7f51\u7edc'],
|
||||
{'name': u'\u7f51\u7edc',
|
||||
'description': u'\u7f51\u7edc'}
|
||||
)
|
||||
|
||||
def test_create_security_group_rule_full(self):
|
||||
"""Create security group rule."""
|
||||
resource = 'security_group_rule'
|
||||
|
||||
Reference in New Issue
Block a user