Skip to content

Commit 83675e9

Browse files
author
judy-yu
committed
Avoid duplicated project_id when show network resources
Project_id appear twice when show network resources. This patch check and not append if it already has one. Change-Id: I744988f3f52d4a744e397a6a82fefdc4c17eacbf Closes-Bug: #1636123 Partially-Implements: blueprint duplicated-project-id
1 parent e05c8d7 commit 83675e9

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def _get_columns(item):
5050
columns = list(item.keys())
5151
if 'tenant_id' in columns:
5252
columns.remove('tenant_id')
53-
columns.append('project_id')
53+
if 'project_id' not in columns:
54+
columns.append('project_id')
5455
binding_columns = [
5556
'binding:host_id',
5657
'binding:profile',

openstackclient/network/v2/router.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from openstackclient.i18n import _
2727
from openstackclient.identity import common as identity_common
28+
from openstackclient.network import sdk_utils
2829

2930

3031
LOG = logging.getLogger(__name__)
@@ -59,11 +60,10 @@ def _format_routes(routes):
5960

6061

6162
def _get_columns(item):
62-
columns = list(item.keys())
63-
if 'tenant_id' in columns:
64-
columns.remove('tenant_id')
65-
columns.append('project_id')
66-
return tuple(sorted(columns))
63+
column_map = {
64+
'tenant_id': 'project_id',
65+
}
66+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
6767

6868

6969
def _get_attrs(client_manager, parsed_args):
@@ -215,10 +215,10 @@ def take_action(self, parsed_args):
215215
attrs['ha'] = parsed_args.ha
216216
obj = client.create_router(**attrs)
217217

218-
columns = _get_columns(obj)
218+
display_columns, columns = _get_columns(obj)
219219
data = utils.get_item_properties(obj, columns, formatters=_formatters)
220220

221-
return (columns, data)
221+
return (display_columns, data)
222222

223223

224224
class DeleteRouter(command.Command):
@@ -523,9 +523,10 @@ def get_parser(self, prog_name):
523523
def take_action(self, parsed_args):
524524
client = self.app.client_manager.network
525525
obj = client.find_router(parsed_args.router, ignore_missing=False)
526-
columns = _get_columns(obj)
526+
display_columns, columns = _get_columns(obj)
527527
data = utils.get_item_properties(obj, columns, formatters=_formatters)
528-
return (columns, data)
528+
529+
return (display_columns, data)
529530

530531

531532
class UnsetRouter(command.Command):

openstackclient/network/v2/security_group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def _get_columns(item):
8181
columns.remove('security_group_rules')
8282
property_column_mappings.append(('rules', 'security_group_rules'))
8383
if 'tenant_id' in columns:
84-
columns.append('project_id')
8584
columns.remove('tenant_id')
85+
if 'project_id' not in columns:
86+
columns.append('project_id')
8687
property_column_mappings.append(('project_id', 'tenant_id'))
8788
display_columns = sorted(columns)
8889

0 commit comments

Comments
 (0)