summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-06-08 12:00:11 +0200
committerDaniil Baturin <daniil@baturin.org>2018-06-08 12:00:11 +0200
commit6acc5f6cb03f553141b0442f5e01cbf47b8e7833 (patch)
tree1f881de6841b6ec6c5a1550c2cab066de8b6330d /src
parent9afd3a8607fe5ce53f3756ea1c2c7045cd7c67b3 (diff)
downloadvyos-1x-6acc5f6cb03f553141b0442f5e01cbf47b8e7833.tar.gz
vyos-1x-6acc5f6cb03f553141b0442f5e01cbf47b8e7833.zip
T689: add a basic library for working with network interfaces and support for interface types to the completion script.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/completion/list_interfaces.py31
1 files changed, 27 insertions, 4 deletions
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))