From 9dbc2c799763f2ea655547ea09abcb816e7163b7 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Tue, 14 May 2013 15:25:13 +0800 Subject: [PATCH] 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 --- quantumclient/quantum/v2_0/securitygroup.py | 25 +++++++++++++++++++++ quantumclient/shell.py | 2 ++ quantumclient/v2_0/client.py | 8 +++++++ tests/unit/test_cli20_securitygroup.py | 23 +++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/quantumclient/quantum/v2_0/securitygroup.py b/quantumclient/quantum/v2_0/securitygroup.py index abc870a3e..c66d012c3 100644 --- a/quantumclient/quantum/v2_0/securitygroup.py +++ b/quantumclient/quantum/v2_0/securitygroup.py @@ -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.""" diff --git a/quantumclient/shell.py b/quantumclient/shell.py index f531325dc..b83b97944 100644 --- a/quantumclient/shell.py +++ b/quantumclient/shell.py @@ -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( diff --git a/quantumclient/v2_0/client.py b/quantumclient/v2_0/client.py index 99f4cde64..e9a5627ce 100644 --- a/quantumclient/v2_0/client.py +++ b/quantumclient/v2_0/client.py @@ -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): """ diff --git a/tests/unit/test_cli20_securitygroup.py b/tests/unit/test_cli20_securitygroup.py index b1e9e32c6..4302093e1 100644 --- a/tests/unit/test_cli20_securitygroup.py +++ b/tests/unit/test_cli20_securitygroup.py @@ -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'