Skip to content

Commit c76e631

Browse files
committed
SDK Refactor: Prepare security group rule commands
Prepare the OSC "security group rule" commands for the SDK refactor. See [1] for details. [1] https://etherpad.openstack.org/p/osc-network-command-sdk-support Change-Id: I5553e40fe90f3a26d3f462a69f1a424032479d49 Partially-Implements: blueprint network-command-sdk-support
1 parent d6e058f commit c76e631

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

openstackclient/network/v2/security_group_rule.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from openstackclient.i18n import _
3030
from openstackclient.identity import common as identity_common
3131
from openstackclient.network import common
32+
from openstackclient.network import sdk_utils
3233
from openstackclient.network import utils as network_utils
3334

3435

@@ -67,11 +68,10 @@ def _format_network_port_range(rule):
6768

6869

6970
def _get_columns(item):
70-
columns = list(item.keys())
71-
if 'tenant_id' in columns:
72-
columns.remove('tenant_id')
73-
columns.append('project_id')
74-
return tuple(sorted(columns))
71+
column_map = {
72+
'tenant_id': 'project_id',
73+
}
74+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
7575

7676

7777
def _convert_to_lowercase(string):
@@ -89,6 +89,8 @@ def _is_icmp_protocol(protocol):
8989
return False
9090

9191

92+
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
93+
# OSC minimum requirements include SDK 1.0.
9294
class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
9395
_description = _("Create a new security group rule")
9496

@@ -341,9 +343,9 @@ def take_action_network(self, client, parsed_args):
341343

342344
# Create and show the security group rule.
343345
obj = client.create_security_group_rule(**attrs)
344-
columns = _get_columns(obj)
346+
display_columns, columns = _get_columns(obj)
345347
data = utils.get_item_properties(obj, columns)
346-
return (columns, data)
348+
return (display_columns, data)
347349

348350
def take_action_compute(self, client, parsed_args):
349351
group = utils.find_resource(
@@ -597,9 +599,9 @@ def update_parser_common(self, parser):
597599
def take_action_network(self, client, parsed_args):
598600
obj = client.find_security_group_rule(parsed_args.rule,
599601
ignore_missing=False)
600-
columns = _get_columns(obj)
602+
display_columns, columns = _get_columns(obj)
601603
data = utils.get_item_properties(obj, columns)
602-
return (columns, data)
604+
return (display_columns, data)
603605

604606
def take_action_compute(self, client, parsed_args):
605607
# NOTE(rtheis): Unfortunately, compute does not have an API

0 commit comments

Comments
 (0)