def do_host_port_list(cc, args): """List host ports.""" from cgtsclient.common import wrapping_formatters terminal_width = utils.get_terminal_size()[0] ihost = ihost_utils._find_ihost(cc, args.hostnameorid) ports = cc.port.list(ihost.uuid) field_labels = ['uuid', 'name', 'type', 'pci address', 'device', 'processor', 'accelerated', 'device type'] fields = ['uuid', 'name', 'type', 'pciaddr', 'dev_id', 'numa_node', 'dpdksupport', 'pdevice'] format_spec = wrapping_formatters.build_best_guess_formatters_using_average_widths(ports, fields, field_labels, no_wrap_fields=['pciaddr']) # best-guess formatter does not make a good guess for # proper width of pdevice until terminal is > 155 # We override that width here. pdevice_width = None if terminal_width <= 130: pdevice_width = .1 elif 131 >= terminal_width <= 150: pdevice_width = .13 elif 151 >= terminal_width <= 155: pdevice_width = .14 if pdevice_width and format_spec["pdevice"] > pdevice_width: format_spec["pdevice"] = pdevice_width formatters = wrapping_formatters.build_wrapping_formatters(ports, fields, field_labels, format_spec) utils.print_list(ports, fields, field_labels, formatters=formatters, sortby=1)
def _get_terminal_width(): from cgtsclient.common.utils import get_terminal_size result = get_terminal_size()[0] return result