diff options
| author | Richard Theis <rtheis@us.ibm.com> | 2016-02-09 07:21:01 -0600 |
|---|---|---|
| committer | Richard Theis <rtheis@us.ibm.com> | 2016-02-29 14:46:57 -0600 |
| commit | 842882f3cbfca6df9a42bc49b0deefdb84509a8e (patch) | |
| tree | 72edcbb413c01582ec4899b925e37306a88cfc5d /openstackclient/network/v2 | |
| parent | 5310cfb8b750b3a17b99d235318e736023cfd234 (diff) | |
| download | python-openstackclient-842882f3cbfca6df9a42bc49b0deefdb84509a8e.tar.gz | |
Refactor security group list to use SDK
Refactored the 'os security group list' command to use the SDK
when neutron is enabled, but continue to use the nova client
when nova network is enabled.
This refactor also removes the logic for displaying project names
instead of project IDs when the --all-projects option is specified.
This logic was removed because it is inconsistent with the other
network commands.
Since neutron will always display security groups across all
projects for an admin, the --all-projects option is now hidden
when neutron is enabled and the Project column is always
displayed.
Change-Id: I934a1f5084ef3c5f929d0ffd38ebf5064d799941
Partial-Bug: #1519511
Related-to: blueprint neutron-client
Diffstat (limited to 'openstackclient/network/v2')
| -rw-r--r-- | openstackclient/network/v2/security_group.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index 4e122f21..29d82b08 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -13,6 +13,8 @@ """Security Group action implementations""" +import argparse + from openstackclient.common import utils from openstackclient.network import common @@ -38,3 +40,51 @@ class DeleteSecurityGroup(common.NetworkAndComputeCommand): parsed_args.group, ) client.security_groups.delete(data.id) + + +class ListSecurityGroup(common.NetworkAndComputeLister): + """List security groups""" + + def update_parser_network(self, parser): + # Maintain and hide the argument for backwards compatibility. + # Network will always return all projects for an admin. + parser.add_argument( + '--all-projects', + action='store_true', + default=False, + help=argparse.SUPPRESS, + ) + return parser + + def update_parser_compute(self, parser): + parser.add_argument( + '--all-projects', + action='store_true', + default=False, + help='Display information from all projects (admin only)', + ) + return parser + + def _get_return_data(self, data, include_project=True): + columns = ( + "ID", + "Name", + "Description", + ) + column_headers = columns + if include_project: + columns = columns + ('Tenant ID',) + column_headers = column_headers + ('Project',) + return (column_headers, + (utils.get_item_properties( + s, columns, + ) for s in data)) + + def take_action_network(self, client, parsed_args): + return self._get_return_data(client.security_groups()) + + def take_action_compute(self, client, parsed_args): + search = {'all_tenants': parsed_args.all_projects} + data = client.security_groups.list(search_opts=search) + return self._get_return_data(data, + include_project=parsed_args.all_projects) |
