summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-08 14:17:29 +0100
committerChristian Poessinger <christian@poessinger.com>2020-03-08 14:17:31 +0100
commitc5715ca7086b0687e3ee95a24ab72ab9b389b323 (patch)
tree98ac54b325a57a5db6f02f010161801ce5ce18d7 /src/op_mode
parentd61cab413307e0b235316e6bb2dbf1ed26e11590 (diff)
downloadvyos-1x-c5715ca7086b0687e3ee95a24ab72ab9b389b323.tar.gz
vyos-1x-c5715ca7086b0687e3ee95a24ab72ab9b389b323.zip
vrf: T31: add member interfaces to 'show ver' output
VRF name state mac address flags interfaces -------- ----- ----------- ----- ---------- blue up de:c4:83:d8:74:24 noarp,master,up,lower_up dum200,eth0.302 red up be:36:ce:02:df:aa noarp,master,up,lower_up dum100,eth0.300,bond0.100,peth0
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/show_vrf.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/op_mode/show_vrf.py b/src/op_mode/show_vrf.py
index ec894d572..66c33e607 100755
--- a/src/op_mode/show_vrf.py
+++ b/src/op_mode/show_vrf.py
@@ -15,15 +15,30 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
+import jinja2
from subprocess import check_output
from json import loads
+vrf_out_tmpl = """
+VRF name state mac address flags interfaces
+-------- ----- ----------- ----- ----------
+{%- for v in vrf %}
+{{"%-16s"|format(v.ifname)}} {{ "%-8s"|format(v.operstate | lower())}} {{"%-17s"|format(v.address | lower())}} {{ v.flags|join(',')|lower()}} {{v.members|join(',')|lower()}}
+{%- endfor %}
+
+"""
+
def list_vrfs():
command = 'ip -j -br link show type vrf'
answer = loads(check_output(command.split()).decode())
return [_ for _ in answer if _]
+def list_vrf_members(vrf):
+ command = f'ip -j -br link show master {vrf}'
+ answer = loads(check_output(command.split()).decode())
+ return [_ for _ in answer if _]
+
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("-e", "--extensive", action="store_true",
@@ -34,15 +49,19 @@ parser.add_argument('interface', metavar='I', type=str, nargs='?',
args = parser.parse_args()
if args.extensive:
- print('{:16} {:7} {:17} {}'.format('interface', 'state', 'mac', 'flags'))
- print('{:16} {:7} {:17} {}'.format('---------', '-----', '---', '-----'))
+ data = { 'vrf': [] }
for vrf in list_vrfs():
name = vrf['ifname']
if args.interface and name != args.interface:
continue
- state = vrf['operstate'].lower()
- mac = vrf['address'].lower()
- info = ','.join([_.lower() for _ in vrf['flags']])
- print(f'{name:16} {state:7} {mac:17} {info}')
+
+ vrf['members'] = []
+ for member in list_vrf_members(name):
+ vrf['members'].append(member['ifname'])
+ data['vrf'].append(vrf)
+
+ tmpl = jinja2.Template(vrf_out_tmpl)
+ print(tmpl.render(data))
+
else:
print(" ".join([vrf['ifname'] for vrf in list_vrfs()]))