diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-03-05 16:08:20 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-03-05 16:08:20 +0000 |
| commit | 0b2c4b1f327dddce0306637e7128bad6eb43fc54 (patch) | |
| tree | ce3c1cff2670f9a6582a1931a6c8d9b56c50ac2a /openstackclient/network | |
| parent | fa3a34322c532c6ae09b7b21c305b6a92d99300a (diff) | |
| parent | bac9fb18c1455f6a309e7acff9230a8d6bf7079b (diff) | |
| download | python-openstackclient-0b2c4b1f327dddce0306637e7128bad6eb43fc54.tar.gz | |
Merge "Refactor security group set to use SDK"
Diffstat (limited to 'openstackclient/network')
| -rw-r--r-- | openstackclient/network/v2/security_group.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index 29d82b08..9cefb420 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -88,3 +88,59 @@ class ListSecurityGroup(common.NetworkAndComputeLister): data = client.security_groups.list(search_opts=search) return self._get_return_data(data, include_project=parsed_args.all_projects) + + +class SetSecurityGroup(common.NetworkAndComputeCommand): + """Set security group properties""" + + def update_parser_common(self, parser): + parser.add_argument( + 'group', + metavar='<group>', + help='Security group to modify (name or ID)', + ) + parser.add_argument( + '--name', + metavar='<new-name>', + help='New security group name', + ) + parser.add_argument( + "--description", + metavar="<description>", + help="New security group description", + ) + return parser + + def take_action_network(self, client, parsed_args): + obj = client.find_security_group(parsed_args.group, + ignore_missing=False) + attrs = {} + if parsed_args.name is not None: + attrs['name'] = parsed_args.name + if parsed_args.description is not None: + attrs['description'] = parsed_args.description + # NOTE(rtheis): Previous behavior did not raise a CommandError + # if there were no updates. Maintain this behavior and issue + # the update. + client.update_security_group(obj, **attrs) + return + + def take_action_compute(self, client, parsed_args): + data = utils.find_resource( + client.security_groups, + parsed_args.group, + ) + + if parsed_args.name is not None: + data.name = parsed_args.name + if parsed_args.description is not None: + data.description = parsed_args.description + + # NOTE(rtheis): Previous behavior did not raise a CommandError + # if there were no updates. Maintain this behavior and issue + # the update. + client.security_groups.update( + data, + data.name, + data.description, + ) |
