config/sysinv/cgts-client/cgts-client/cgtsclient/v1/ethernetport_shell.py
Al Bailey d7330d0f44 Convert cgtsclient from setuptools to pbr. Add tox.
Primary reason for this change was to update the spec and setup files
from basic setuptools to use pbr
This allows the autogenerated  /usr/bin/system file to directly call the
main method without using pkg-resources.
This will provide a performance improvement of .5 seconds per CLI call,
once the other pkg_resources issues are resolved

Second reason for this change was to wire in the tox unit tests.  This
also includes pep8, pylint and coverage.
Currently pep8 does not perform the 80 char limit check
Currently pylint still reports some issues

This should not affect the RPM names being generated or otherwise affect
patching or upgrades.

Change-Id: I9f14c9216fdcc63930a4b2849102b58442706144
2018-06-28 22:07:37 -04:00

86 lines
2.7 KiB
Python

#!/usr/bin/env python
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#
from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.v1 import ihost as ihost_utils
def _bootp_formatter(value):
return bool(value)
def _bootp_port_formatter(port):
return _bootp_formatter(port.bootp)
def _print_ethernet_port_show(port):
fields = ['name', 'namedisplay',
'mac', 'pciaddr',
'numa_node',
'autoneg', 'bootp',
'pclass', 'pvendor', 'pdevice',
'link_mode', 'capabilities',
'uuid', 'host_uuid', 'interface_uuid',
'created_at', 'updated_at']
labels = ['name', 'namedisplay',
'mac', 'pciaddr',
'processor',
'autoneg', 'bootp',
'pclass', 'pvendor', 'pdevice',
'link_mode', 'capabilities',
'uuid', 'host_uuid', 'interface_uuid',
'created_at', 'updated_at']
data = [(f, getattr(port, f, '')) for f in fields]
utils.print_tuple_list(data, labels,
formatters={'bootp': _bootp_formatter})
def _find_port(cc, ihost, portnameoruuid):
ports = cc.ethernet_port.list(ihost.uuid)
for p in ports:
if p.name == portnameoruuid or p.uuid == portnameoruuid:
break
else:
raise exc.CommandError('Ethernet port not found: host %s port %s' % (ihost.id, portnameoruuid))
p.autoneg = 'Yes' # TODO(jkung) Remove when autoneg supported in DB
return p
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of host")
@utils.arg('pnameoruuid', metavar='<port name or uuid>', help="Name or UUID of port")
def do_host_ethernet_port_show(cc, args):
"""Show host ethernet port attributes."""
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
port = _find_port(cc, ihost, args.pnameoruuid)
_print_ethernet_port_show(port)
@utils.arg('hostnameorid',
metavar='<hostname or id>',
help="Name or ID of host")
def do_host_ethernet_port_list(cc, args):
"""List host ethernet ports."""
ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
ports = cc.ethernet_port.list(ihost.uuid)
for p in ports:
p.autoneg = 'Yes' # TODO(jkung) Remove when autoneg supported in DB
field_labels = ['uuid', 'name', 'mac address', 'pci address', 'processor', 'auto neg', 'device type', 'boot i/f']
fields = ['uuid', 'name', 'mac', 'pciaddr', 'numa_node', 'autoneg', 'pdevice', 'bootp']
utils.print_list(ports, fields, field_labels, sortby=1,
formatters={'bootp': _bootp_port_formatter})