diff options
| author | Richard Theis <rtheis@us.ibm.com> | 2016-03-01 15:34:35 -0600 |
|---|---|---|
| committer | Richard Theis <rtheis@us.ibm.com> | 2016-03-10 10:18:52 -0600 |
| commit | ea2dd8e141ef1cf446a42ee93992d8fb44f4ba05 (patch) | |
| tree | 81212e681eb41a7e40bf432e1e4a7bec41da87dc /openstackclient/network/v2/security_group.py | |
| parent | 564c8ff2403da87b96562076865f42426a4f8eac (diff) | |
| download | python-openstackclient-ea2dd8e141ef1cf446a42ee93992d8fb44f4ba05.tar.gz | |
Refactor security group create to use SDK
Refactored the 'os security group create' command to use the SDK
when neutron is enabled, but continue to use the nova client
when nova network is enabled.
Added a release note for the change in security group rules output
due to Network v2. The tenant_id column name was fixed to align
with the 'os security group show' command.
Change-Id: Ib29df42edcddcc73a123fff6a64743a6bfcb7fbf
Partial-Bug: #1519511
Implements: blueprint neutron-client
Diffstat (limited to 'openstackclient/network/v2/security_group.py')
| -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 64717945..f8162477 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -91,6 +91,56 @@ def _get_columns(item): return tuple(display_columns), property_columns +class CreateSecurityGroup(common.NetworkAndComputeShowOne): + """Create a new security group""" + + def update_parser_common(self, parser): + parser.add_argument( + "name", + metavar="<name>", + help="New security group name", + ) + parser.add_argument( + "--description", + metavar="<description>", + help="Security group description", + ) + return parser + + def _get_description(self, parsed_args): + if parsed_args.description is not None: + return parsed_args.description + else: + return parsed_args.name + + def take_action_network(self, client, parsed_args): + attrs = {} + attrs['name'] = parsed_args.name + attrs['description'] = self._get_description(parsed_args) + obj = client.create_security_group(**attrs) + display_columns, property_columns = _get_columns(obj) + data = utils.get_item_properties( + obj, + property_columns, + formatters=_formatters_network + ) + return (display_columns, data) + + def take_action_compute(self, client, parsed_args): + description = self._get_description(parsed_args) + obj = client.security_groups.create( + parsed_args.name, + description, + ) + display_columns, property_columns = _get_columns(obj._info) + data = utils.get_dict_properties( + obj._info, + property_columns, + formatters=_formatters_compute + ) + return (display_columns, data) + + class DeleteSecurityGroup(common.NetworkAndComputeCommand): """Delete a security group""" |
