From 1cf320302bee2e406ed7189d3cf3d08542770637 Mon Sep 17 00:00:00 2001 From: Terry Howe <terrylhowe@gmail.com> Date: Thu, 10 Dec 2015 14:58:16 -0700 Subject: [PATCH] Map some of the SDK field names The keys() method returns the keys returned from Neutron, but the SDK maps some things like tenant_id to project_id. This makes the output a little prettier. Change-Id: Ibd8c890b61ffc94021f93fc1051fcf5dabd1e9ea --- openstackclient/network/v2/network.py | 19 +++++++++++++++---- openstackclient/tests/network/v2/fakes.py | 5 ++++- .../tests/network/v2/test_network.py | 14 +++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 519356b4f7..6b2062dd10 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -39,6 +39,17 @@ _formatters = { } +def _get_columns(item): + columns = item.keys() + if 'tenant_id' in columns: + columns.remove('tenant_id') + columns.append('project_id') + if 'router:external' in columns: + columns.remove('router:external') + columns.append('router_external') + return tuple(sorted(columns)) + + class CreateNetwork(show.ShowOne): """Create new network""" @@ -91,9 +102,9 @@ class CreateNetwork(show.ShowOne): client = self.app.client_manager.network body = self.get_body(parsed_args) obj = client.create_network(**body) - columns = sorted(obj.keys()) + columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) - return (tuple(columns), data) + return (columns, data) def get_body(self, parsed_args): body = {'name': str(parsed_args.name), @@ -292,6 +303,6 @@ class ShowNetwork(show.ShowOne): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.network obj = client.find_network(parsed_args.identifier, ignore_missing=False) - columns = sorted(obj.keys()) + columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) - return (tuple(columns), data) + return (columns, data) diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index abb88ee478..0e601a72ac 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -73,11 +73,12 @@ class FakeNetwork(object): router_external, status, subnets, tenant_id """ # Set default attributes. + project_id = 'project-id-' + uuid.uuid4().hex network_attrs = { 'id': 'network-id-' + uuid.uuid4().hex, 'name': 'network-name-' + uuid.uuid4().hex, 'status': 'ACTIVE', - 'tenant_id': 'project-id-' + uuid.uuid4().hex, + 'tenant_id': project_id, 'admin_state_up': True, 'shared': False, 'subnets': ['a', 'b'], @@ -101,6 +102,8 @@ class FakeNetwork(object): network = fakes.FakeResource(info=copy.deepcopy(network_attrs), methods=copy.deepcopy(network_methods), loaded=True) + network.project_id = project_id + return network @staticmethod diff --git a/openstackclient/tests/network/v2/test_network.py b/openstackclient/tests/network/v2/test_network.py index e86514927a..df61b0db28 100644 --- a/openstackclient/tests/network/v2/test_network.py +++ b/openstackclient/tests/network/v2/test_network.py @@ -44,20 +44,20 @@ class TestCreateNetworkIdentityV3(TestNetwork): 'admin_state_up', 'id', 'name', + 'project_id', 'router_external', 'status', 'subnets', - 'tenant_id', ) data = ( network._format_admin_state(_network.admin_state_up), _network.id, _network.name, + _network.project_id, network._format_router_external(_network.router_external), _network.status, utils.format_list(_network.subnets), - _network.tenant_id, ) def setUp(self): @@ -176,20 +176,20 @@ class TestCreateNetworkIdentityV2(TestNetwork): 'admin_state_up', 'id', 'name', + 'project_id', 'router_external', 'status', 'subnets', - 'tenant_id', ) data = ( network._format_admin_state(_network.admin_state_up), _network.id, _network.name, + _network.project_id, network._format_router_external(_network.router_external), _network.status, utils.format_list(_network.subnets), - _network.tenant_id, ) def setUp(self): @@ -330,7 +330,7 @@ class TestListNetwork(TestNetwork): net.id, net.name, net.status, - net.tenant_id, + net.project_id, network._format_admin_state(net.admin_state_up), net.shared, utils.format_list(net.subnets), @@ -475,20 +475,20 @@ class TestShowNetwork(TestNetwork): 'admin_state_up', 'id', 'name', + 'project_id', 'router_external', 'status', 'subnets', - 'tenant_id', ) data = ( network._format_admin_state(_network.admin_state_up), _network.id, _network.name, + _network.project_id, network._format_router_external(_network.router_external), _network.status, utils.format_list(_network.subnets), - _network.tenant_id, ) def setUp(self):