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 <patrick.bonnell@windriver.com>
This commit is contained in:
Patrick Bonnell 2018-09-14 12:05:55 -04:00
parent ee732ad8f5
commit 3a5e7c6fd6
2 changed files with 19 additions and 5 deletions

View File

@ -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)

View File

@ -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: