From 8bc12847568582d3b34f3859946470af1344f9ea Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 11 Apr 2020 16:42:40 +0100 Subject: completion: T2238: use interface data Use the data in the default dict of the interface to generate the output of list interface. --- src/completion/list_interfaces.py | 40 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'src/completion') 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())) -- cgit v1.2.3