summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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()))