diff options
| author | Richard Theis <rtheis@us.ibm.com> | 2016-03-02 15:45:01 -0600 |
|---|---|---|
| committer | Richard Theis <rtheis@us.ibm.com> | 2016-03-03 06:33:15 -0600 |
| commit | bac9fb18c1455f6a309e7acff9230a8d6bf7079b (patch) | |
| tree | 64ecbaf197640b7a76f4296cd1f65062f77cb9f6 /openstackclient/network | |
| parent | f9add0559c52bf3d0866cfbd320982c5143f6ef6 (diff) | |
| download | python-openstackclient-bac9fb18c1455f6a309e7acff9230a8d6bf7079b.tar.gz | |
Refactor security group set to use SDK
Refactored the 'os security group set' command to use the SDK
when neutron is enabled, but continue to use the nova client
when nova network is enabled.
This patch set also fixes a compute bug which ignores name
and description when set to an empty value.
Change-Id: I4225179dca4aedf799e1656ec49236bdedc5e9bd
Partial-Bug: #1519511
Implements: blueprint neutron-client
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, + ) |
