listboxes: show router ports

This commit is contained in:
2025-04-09 11:40:32 +02:00
parent 420db466f1
commit ef3ee7775a

View File

@ -23,20 +23,42 @@ def check_ssh(host, port=22):
opt = sys.argv[-1] opt = sys.argv[-1]
header = ['box name', 'box type', 'frappy', 'R'] if opt.startswith('-'):
if opt != 's': opt = opt[1:]
header = ['box name', 'box type', 'frappy']
if opt == 's':
header.append('R')
else:
if opt == 'a': if opt == 'a':
header.extend(['*online ip ', 'MAC addr']) header.extend(['router', '*online ip ', 'MAC addr'])
else: else:
header.append('ip') header.extend(['R', 'ip'])
table = [header] table = [header]
for file in sorted(cfgdir.glob('*.cfg')): for file in sorted(cfgdir.glob('*.cfg')):
parser = ConfigParser() parser = ConfigParser()
parser.read(file) parser.read(file)
info = {k: dict(parser[k]) for k in parser.sections()} info = {k: dict(parser[k]) for k in parser.sections()}
router = info.get('ROUTER') router = info.get('ROUTER', {})
router = 'R' if router else '' if opt == 'a':
ports = sorted(router)
router = []
following = None
for p in ports:
try:
pnum = int(p)
if pnum == following:
first = router[-1].split('-')[0]
router[-1] = f'{first}-{following}'
following += 1
continue
following = pnum + 1
except ValueError:
pnum = -1
router.append(p)
router = ' '.join(router)
else:
router = 'R' if router else ''
frappy = info.get('FRAPPY', {}).get('cfg', '') frappy = info.get('FRAPPY', {}).get('cfg', '')
box = info.get('BOX', {}) box = info.get('BOX', {})
row = [file.stem, box.get('type', 'unknown'), frappy, router] row = [file.stem, box.get('type', 'unknown'), frappy, router]
@ -68,6 +90,8 @@ Usage:
listboxes o # only boxes online (default) listboxes o # only boxes online (default)
listboxes a # all boxes, all info listboxes a # all boxes, all info
listboxes s # short (without ip and online check) listboxes s # short (without ip and online check)
column R: router configured
""" """
if opt in 'sao': if opt in 'sao':
print() print()