listboxes: show router ports
This commit is contained in:
36
listboxes
36
listboxes
@ -23,19 +23,41 @@ 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:]
|
||||||
if opt == 'a':
|
header = ['box name', 'box type', 'frappy']
|
||||||
header.extend(['*online ip ', 'MAC addr'])
|
if opt == 's':
|
||||||
|
header.append('R')
|
||||||
else:
|
else:
|
||||||
header.append('ip')
|
if opt == 'a':
|
||||||
|
header.extend(['router', '*online ip ', 'MAC addr'])
|
||||||
|
else:
|
||||||
|
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', {})
|
||||||
|
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 ''
|
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', {})
|
||||||
@ -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()
|
||||||
|
Reference in New Issue
Block a user