Skip to content

Commit 9dbc2c7

Browse files
committed
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
1 parent d477346 commit 9dbc2c7

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

quantumclient/quantum/v2_0/securitygroup.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ class DeleteSecurityGroup(quantumv20.DeleteCommand):
7373
allow_names = True
7474

7575

76+
class UpdateSecurityGroup(quantumv20.UpdateCommand):
77+
"""Update a given security group."""
78+
79+
log = logging.getLogger(__name__ + '.UpdateSecurityGroup')
80+
resource = 'security_group'
81+
82+
def add_known_arguments(self, parser):
83+
parser.add_argument(
84+
'--name',
85+
help='Name of security group')
86+
parser.add_argument(
87+
'--description',
88+
help='description of security group')
89+
90+
def args2body(self, parsed_args):
91+
body = {'security_group': {}}
92+
if parsed_args.name:
93+
body['security_group'].update(
94+
{'name': parsed_args.name})
95+
if parsed_args.description:
96+
body['security_group'].update(
97+
{'description': parsed_args.description})
98+
return body
99+
100+
76101
class ListSecurityGroupRule(quantumv20.ListCommand):
77102
"""List security group rules that belong to a given tenant."""
78103

quantumclient/shell.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def env(*_vars, **kwargs):
150150
'quantumclient.quantum.v2_0.securitygroup.CreateSecurityGroup'),
151151
'security-group-delete': utils.import_class(
152152
'quantumclient.quantum.v2_0.securitygroup.DeleteSecurityGroup'),
153+
'security-group-update': utils.import_class(
154+
'quantumclient.quantum.v2_0.securitygroup.UpdateSecurityGroup'),
153155
'security-group-rule-list': utils.import_class(
154156
'quantumclient.quantum.v2_0.securitygroup.ListSecurityGroupRule'),
155157
'security-group-rule-show': utils.import_class(

quantumclient/v2_0/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@ def create_security_group(self, body=None):
470470
"""
471471
return self.post(self.security_groups_path, body=body)
472472

473+
@APIParamsCall
474+
def update_security_group(self, security_group, body=None):
475+
"""
476+
Updates a security group
477+
"""
478+
return self.put(self.security_group_path %
479+
security_group, body=body)
480+
473481
@APIParamsCall
474482
def list_security_groups(self, retrieve_all=True, **_params):
475483
"""

tests/unit/test_cli20_securitygroup.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ def test_delete_security_group(self):
118118
args = [myid]
119119
self._test_delete_resource(resource, cmd, myid, args)
120120

121+
def test_update_security_group(self):
122+
"""Update security group: myid --name myname --description desc."""
123+
resource = 'security_group'
124+
cmd = securitygroup.UpdateSecurityGroup(
125+
test_cli20.MyApp(sys.stdout), None)
126+
self._test_update_resource(resource, cmd, 'myid',
127+
['myid', '--name', 'myname',
128+
'--description', 'mydescription'],
129+
{'name': 'myname',
130+
'description': 'mydescription'}
131+
)
132+
133+
def test_update_security_group_with_unicode(self):
134+
resource = 'security_group'
135+
cmd = securitygroup.UpdateSecurityGroup(
136+
test_cli20.MyApp(sys.stdout), None)
137+
self._test_update_resource(resource, cmd, 'myid',
138+
['myid', '--name', u'\u7f51\u7edc',
139+
'--description', u'\u7f51\u7edc'],
140+
{'name': u'\u7f51\u7edc',
141+
'description': u'\u7f51\u7edc'}
142+
)
143+
121144
def test_create_security_group_rule_full(self):
122145
"""Create security group rule."""
123146
resource = 'security_group_rule'

0 commit comments

Comments
 (0)