#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
import argparse import json import pathlib import pprint import sys import re import os
sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix()) from lib import YnlFamily from cli import schema_dir, spec_dir
def args_to_req(ynl, op_name, args, req): """
Verify and convert command-line arguments to the ynl-compatible request. """
valid_attrs = ynl.operation_do_attributes(op_name)
valid_attrs.remove('header') # not user-provided
if len(args) == 0:
print(f'no attributes, expected: {valid_attrs}')
sys.exit(1)
i = 0 while i < len(args):
attr = args[i] if i + 1 >= len(args):
print(f'expected value for \'{attr}\'')
sys.exit(1)
if attr notin valid_attrs:
print(f'invalid attribute \'{attr}\', expected: {valid_attrs}')
sys.exit(1)
val = args[i+1]
i += 2
req[attr] = val
def print_field(reply, *desc): """
Pretty-print a set of fields from the reply. desc specifies the
fields and the optional type (bool/yn). """ ifnot reply: return
if len(desc) == 0: return print_field(reply, *zip(reply.keys(), reply.keys()))
for spec in desc: try:
field, name, tp = spec except:
field, name = spec
tp = 'int'
value = reply.get(field, None) if tp == 'yn':
value = 'yes'if value else'no' elif tp == 'bool'or isinstance(value, bool):
value = 'on'if value else'off' else:
value = 'n/a'if value isNoneelse value
print(f'{name}: {value}')
def print_speed(name, value): """
Print out the speed-like strings from the value dict. """
speed_re = re.compile(r'[0-9]+base[^/]+/.+')
speed = [ k for k, v in value.items() if v and speed_re.match(k) ]
print(f'{name}: {" ".join(speed)}')
def dumpit(ynl, args, op_name, extra = {}): """
Prepare request header, parse arguments and dumpit (filtering out the
devices we're not interested in). """
reply = ynl.dump(op_name, { 'header': {} } | extra) ifnot reply: return {}
for msg in reply: if msg['header']['dev-name'] == args.device: if args.json:
pprint.PrettyPrinter().pprint(msg)
sys.exit(0)
msg.pop('header', None) return msg
print(f"Not supported for device {args.device}")
sys.exit(1)
def bits_to_dict(attr): """
Convert ynl-formatted bitmask to a dict of bit=value. """
ret = {} if'bits'notin attr: return dict() if'bit'notin attr['bits']: return dict() for bit in attr['bits']['bit']: if bit['name'] == '': continue
name = bit['name']
value = bit.get('value', False)
ret[name] = value return ret
if'enabled'in eee:
status = 'enabled'if eee['enabled'] else'disabled' if'active'in eee and eee['active']:
status = status + ' - active' else:
status = status + ' - inactive' else:
status = 'not supported'
print(f'EEE status: {status}')
print_field(eee, ('tx-lpi-timer', 'Tx LPI'))
print_speed('Advertised EEE link modes', ours)
print_speed('Link partner advertised EEE link modes', peer)
supported_ports = ('TP', 'AUI', 'BNC', 'MII', 'FIBRE', 'Backplane')
ports = [ p for p in supported_ports if ours.get(p, False)]
print(f'Supported ports: [ {" ".join(ports)} ]')
supported_fec = ('None', 'PS', 'BASER', 'LLRS')
fec = [ p for p in supported_fec if ours.get(p, False)]
fec_str = " ".join(fec) if len(fec) == 0:
fec_str = "Not reported"
print(f'Supported FEC modes: {fec_str}')
speed = 'Unknown!' if linkmodes['speed'] > 0 and linkmodes['speed'] < 0xffffffff:
speed = f'{linkmodes["speed"]}Mb/s'
print(f'Speed: {speed}')
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.