diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-03-04 22:02:26 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-03-04 22:02:26 +0100 |
commit | 10ef1bb6c4a8e02081660eddf5918c92151382b7 (patch) | |
tree | 31885f0a2b32b0db18f9e44b634e9176c5de54f0 /src/op_mode | |
parent | 1257c0126bdc10bba605652f624815b2e0350ca2 (diff) | |
parent | 153d1535d954f59cc48ed26f6cc552703b8cbd73 (diff) | |
download | vyos-1x-10ef1bb6c4a8e02081660eddf5918c92151382b7.tar.gz vyos-1x-10ef1bb6c4a8e02081660eddf5918c92151382b7.zip |
Merge branch 't31-vrf' of github.com:c-po/vyos-1x into current
* 't31-vrf' of github.com:c-po/vyos-1x:
vrf: T31: enable vrf support for dummy interface
templates: T2099: make op-mode path completion helper working
vrf: T31: reorder routing table lookups
vrf: T31: adding unreachable routes to the routing tables
vrf: T31: prior to the v4.8 kernel iif and oif rules are needed
vrf: T31: create iproute2 table to name mapping reference
vrf: T31: rename 'vrf disable-bind-to-all ipv4' to 'vrf bind-to-all'
vrf: T31: support add/remove of interfaces from vrf
vrf: T31: remove superfluous vyos.vrf library functions
vrf: T31: reduce script complexity
vrf: T31: no need to use sudo calls in vrf.py
vrf: T31: make 'show vrf' command behave like other 'show interface commands'
xml: include: description: adjust help message
vrf: T31: improve help for routing table
vrf: T31: reuse interface-description.xml.i for instance description
vrf: T31: use embedded regex on 'vrf name' instead of python script
vrf: T31: initial support for a VRF backend in XML/Python
ifconfig: T2057: generic interface option setting
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/show_vrf.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/op_mode/show_vrf.py b/src/op_mode/show_vrf.py new file mode 100755 index 000000000..ec894d572 --- /dev/null +++ b/src/op_mode/show_vrf.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import argparse + +from subprocess import check_output +from json import loads + +def list_vrfs(): + command = 'ip -j -br link show type 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", + help="provide detailed vrf informatio") +parser.add_argument('interface', metavar='I', type=str, nargs='?', + help='interface to display') + +args = parser.parse_args() + +if args.extensive: + print('{:16} {:7} {:17} {}'.format('interface', 'state', 'mac', 'flags')) + print('{:16} {:7} {:17} {}'.format('---------', '-----', '---', '-----')) + 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}') +else: + print(" ".join([vrf['ifname'] for vrf in list_vrfs()])) |