summaryrefslogtreecommitdiff
path: root/src/completion
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-04-11 16:42:40 +0100
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-04-11 19:08:30 +0100
commit8bc12847568582d3b34f3859946470af1344f9ea (patch)
treec4dff573a8262022515247f802c667988e2d30a9 /src/completion
parentd3aa0bd68bb72bc35eb290b1c54cae4dfa4efb57 (diff)
downloadvyos-1x-8bc12847568582d3b34f3859946470af1344f9ea.tar.gz
vyos-1x-8bc12847568582d3b34f3859946470af1344f9ea.zip
completion: T2238: use interface data
Use the data in the default dict of the interface to generate the output of list interface.
Diffstat (limited to 'src/completion')
-rwxr-xr-xsrc/completion/list_interfaces.py40
1 files changed, 12 insertions, 28 deletions
diff --git a/src/completion/list_interfaces.py b/src/completion/list_interfaces.py
index 64aecef60..e27281433 100755
--- a/src/completion/list_interfaces.py
+++ b/src/completion/list_interfaces.py
@@ -4,6 +4,13 @@ import sys
import argparse
from vyos.ifconfig import Section
+
+def matching(feature):
+ for section in Section.feature(feature):
+ for intf in Section.interfaces(section):
+ yield intf
+
+
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("-t", "--type", type=str, help="List interfaces of specific type")
@@ -13,46 +20,23 @@ group.add_argument("-bo", "--bondable", action="store_true", help="List all bond
args = parser.parse_args()
-# XXX: Need to be rewritten using the data in the class definition
-# XXX: It can be done once vti and input are moved into vyos
-# XXX: We store for each class what type they are (broadcast, bridgeabe, ...)
-
if args.type:
try:
interfaces = Section.interfaces(args.type)
-
+ print(" ".join(interfaces))
except ValueError as e:
print(e, file=sys.stderr)
print("")
elif args.broadcast:
- eth = Section.interfaces("ethernet")
- bridge = Section.interfaces("bridge")
- bond = Section.interfaces("bonding")
- interfaces = eth + bridge + bond
+ print(" ".join(matching("broadcast")))
elif args.bridgeable:
- eth = Section.interfaces("ethernet")
- bond = Section.interfaces("bonding")
- l2tpv3 = Section.interfaces("l2tpv3")
- openvpn = Section.interfaces("openvpn")
- wireless = Section.interfaces("wireless")
- tunnel = Section.interfaces("tunnel")
- vxlan = Section.interfaces("vxlan")
- geneve = Section.interfaces("geneve")
-
- interfaces = eth + bond + l2tpv3 + openvpn + vxlan + tunnel + wireless + geneve
+ print(" ".join(matching("bridgeable")))
elif args.bondable:
- interfaces = []
- eth = Section.interfaces("ethernet")
-
# we need to filter out VLAN interfaces identified by a dot (.) in their name
- for intf in eth:
- if not '.' in intf:
- interfaces.append(intf)
+ print(" ".join([intf for intf in matching("bondable") if '.' not in intf]))
else:
- interfaces = Section.interfaces()
-
-print(" ".join(interfaces))
+ print(" ".join(Section.interfaces()))