From 6acc5f6cb03f553141b0442f5e01cbf47b8e7833 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 8 Jun 2018 12:00:11 +0200 Subject: T689: add a basic library for working with network interfaces and support for interface types to the completion script. --- src/completion/list_interfaces.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/completion/list_interfaces.py') diff --git a/src/completion/list_interfaces.py b/src/completion/list_interfaces.py index 59c9dffad..a4968c52f 100755 --- a/src/completion/list_interfaces.py +++ b/src/completion/list_interfaces.py @@ -1,8 +1,31 @@ #!/usr/bin/env python3 -import netifaces +import sys +import argparse -if __name__ == '__main__': - interfaces = netifaces.interfaces() +import vyos.interfaces - print(" ".join(interfaces)) + +parser = argparse.ArgumentParser() +group = parser.add_mutually_exclusive_group() +group.add_argument("-t", "--type", type=str, help="List interfaces of specific type") +group.add_argument("-b", "--broadcast", action="store_true", help="List all broadcast interfaces") + +args = parser.parse_args() + +if args.type: + try: + interfaces = vyos.interfaces.list_interfaces_of_type(args.type) + + except ValueError as e: + print(e, file=sys.stderr) + print("") +elif args.broadcast: + eth = vyos.interfaces.list_interfaces_of_type("ethernet") + bridge = vyos.interfaces.list_interfaces_of_type("bridge") + bond = vyos.interfaces.list_interfaces_of_type("bonding") + interfaces = eth + bridge + bond +else: + interfaces = vyos.interfaces.list_interfaces() + +print(" ".join(interfaces)) -- cgit v1.2.3