From 3a5e7c6fd68061c0581dcb8b54c74ce213cd03fc Mon Sep 17 00:00:00 2001 From: Patrick Bonnell Date: Fri, 14 Sep 2018 12:05:55 -0400 Subject: [PATCH] Display network name in interface show command The command 'host-if-show' will now display the network names rather than the network IDs associated with the interface. Story: 2003087 Task: 26475 Change-Id: Icb89e3214a3db4694b2244b4dd40ed55938bcb2f Signed-off-by: Patrick Bonnell --- .../cgts-client/cgtsclient/v1/iinterface_shell.py | 15 +++++++++++---- .../cgts-client/cgtsclient/v1/network.py | 9 ++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py index d692684f88..2f26b54aec 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py @@ -16,7 +16,7 @@ from cgtsclient.v1 import iinterface as iinterface_utils from cgtsclient.v1 import network as network_utils -def _print_iinterface_show(iinterface): +def _print_iinterface_show(cc, iinterface): fields = ['ifname', 'iftype', 'ports', 'providernetworks', 'imac', 'imtu', 'ifclass', 'networks', 'aemode', 'schedpolicy', 'txhashpolicy', @@ -25,6 +25,13 @@ def _print_iinterface_show(iinterface): 'created_at', 'updated_at', 'sriov_numvfs'] optional_fields = ['ipv4_mode', 'ipv6_mode', 'ipv4_pool', 'ipv6_pool'] rename_fields = [{'field': 'dpdksupport', 'label': 'accelerated'}] + network_names = "" + networks = getattr(iinterface, 'networks', []) + for n in networks: + network = network_utils._find_network(cc, n) + network_names += "{},".format(network.name) + network_names = network_names.strip(',') + setattr(iinterface, 'networks', network_names) data = [(f, getattr(iinterface, f, '')) for f in fields] data += [(f, getattr(iinterface, f, '')) for f in optional_fields if hasattr(iinterface, f)] @@ -56,7 +63,7 @@ def do_host_if_show(cc, args): i = _find_interface(cc, ihost, args.ifnameoruuid) iinterface_utils._get_ports(cc, ihost, i) - _print_iinterface_show(i) + _print_iinterface_show(cc, i) @utils.arg('hostnameorid', @@ -215,7 +222,7 @@ def do_host_if_add(cc, args): raise exc.CommandError('Created Interface UUID not found: %s' % suuid) iinterface_utils._get_ports(cc, ihost, iinterface) - _print_iinterface_show(iinterface) + _print_iinterface_show(cc, iinterface) @utils.arg('hostnameorid', @@ -312,4 +319,4 @@ def do_host_if_modify(cc, args): iinterface = cc.iinterface.update(interface.uuid, patch) iinterface_utils._get_ports(cc, ihost, iinterface) - _print_iinterface_show(iinterface) + _print_iinterface_show(cc, iinterface) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/network.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/network.py index 954893f964..78d9f64b92 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/network.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/network.py @@ -50,7 +50,14 @@ class NetworkManager(base.Manager): def _find_network(cc, network): - if network.isdigit() or utils.is_uuid_like(network): + if network.isdigit() and not utils.is_uuid_like(network): + network_list = cc.network.list() + for n in network_list: + if str(n.id) == network: + return n + else: + raise exc.CommandError('network not found: %s' % network) + elif utils.is_uuid_like(network): try: h = cc.network.get(network) except exc.HTTPNotFound: