diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-23 17:21:49 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-23 17:21:49 +0100 |
commit | ac9f24aa5f801380455597fbde2a89aea98f05f5 (patch) | |
tree | 22e1eb6edb945ebfa3624e98c93eea6a80c751c5 | |
parent | 1ca8fc0b3f75d63f0751305d8d2d6e6a5f72c5e3 (diff) | |
download | vyos-1x-ac9f24aa5f801380455597fbde2a89aea98f05f5.tar.gz vyos-1x-ac9f24aa5f801380455597fbde2a89aea98f05f5.zip |
pppoe: T2223: report the state of pppoe intf
-rw-r--r-- | op-mode-definitions/show-interfaces-pppoe.xml | 2 | ||||
-rwxr-xr-x | src/op_mode/show_interfaces.py | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/op-mode-definitions/show-interfaces-pppoe.xml b/op-mode-definitions/show-interfaces-pppoe.xml index e68d05da9..211ad9808 100644 --- a/op-mode-definitions/show-interfaces-pppoe.xml +++ b/op-mode-definitions/show-interfaces-pppoe.xml @@ -11,7 +11,7 @@ <script>${vyos_completion_dir}/list_pppoe_peers.sh</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/show_interfaces.py pppoe --intf="$4"</command> + <command>${vyos_op_scripts_dir}/show_interfaces.py --intf="$4"</command> <children> <node name="log"> <properties> diff --git a/src/op_mode/show_interfaces.py b/src/op_mode/show_interfaces.py index 8b6690b7d..7041c7e16 100755 --- a/src/op_mode/show_interfaces.py +++ b/src/op_mode/show_interfaces.py @@ -18,6 +18,7 @@ import os import re import sys +import glob import datetime import argparse import netifaces @@ -146,9 +147,20 @@ def run_allowed(**kwarg): sys.stdout.write(' '.join(Section.interfaces())) +def pppoe(ifname): + out = cmd(f'ps -C pppd -f') + if ifname in out: + return 'C' + elif ifname in [_.split('/')[-1] for _ in glob.glob('/etc/ppp/peers/pppoe*')]: + return 'D' + return '' + + @register('show') def run_show_intf(ifnames, iftypes, vif, vrrp): + handled = [] for interface in filtered_interfaces(ifnames, iftypes, vif, vrrp): + handled.append(interface.ifname) cache = interface.operational.load_counters() out = cmd(f'ip addr show {interface.ifname}') @@ -173,6 +185,17 @@ def run_show_intf(ifnames, iftypes, vif, vrrp): print() print(interface.operational.formated_stats()) + for ifname in ifnames: + if ifname not in handled and ifname.startswith('pppoe'): + state = pppoe(ifname) + if not state: + continue + string = { + 'C': 'Coming up', + 'D': 'Link down', + }[state] + print('{}: {}'.format(ifname, string)) + @register('show-brief') def run_show_intf_brief(ifnames, iftypes, vif, vrrp): @@ -183,7 +206,10 @@ def run_show_intf_brief(ifnames, iftypes, vif, vrrp): print(format1 % ("Interface", "IP Address", "S/L", "Description")) print(format1 % ("---------", "----------", "---", "-----------")) + handled = [] for interface in filtered_interfaces(ifnames, iftypes, vif, vrrp): + handled.append(interface.ifname) + oper_state = interface.operational.get_state() admin_state = interface.get_admin_state() @@ -206,6 +232,17 @@ def run_show_intf_brief(ifnames, iftypes, vif, vrrp): print(format2 % (i, a)) print(format1 % ('', '', '/'.join(s+l), d)) + for ifname in ifnames: + if ifname not in handled and ifname.startswith('pppoe'): + state = pppoe(ifname) + if not state: + continue + string = { + 'C': 'u/D', + 'D': 'A/D', + }[state] + print(format1 % (ifname, '', string, '')) + @register('show-count') def run_show_counters(ifnames, iftypes, vif, vrrp): |