summaryrefslogtreecommitdiff
path: root/src/op_mode/show_vrf.py
blob: 210b3c9a4dab2cf3eb8feb867eb6331ff88bbec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3

import argparse
import vyos.vrf

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 vyos.vrf.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 vyos.vrf.list_vrfs()]))