diff options
author | Christian Poessinger <christian@poessinger.com> | 2022-08-25 18:56:25 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2022-08-25 18:57:27 +0200 |
commit | cfde4b4986347d4b050b38c7dc50db9179894a81 (patch) | |
tree | c88a1535f86642fa1990efef91768c49a26bf362 | |
parent | 02e3dbbe53ac15309eb3b809c78ce9f64da1205f (diff) | |
download | vyos-1x-cfde4b4986347d4b050b38c7dc50db9179894a81.tar.gz vyos-1x-cfde4b4986347d4b050b38c7dc50db9179894a81.zip |
ifconfig: T2223: add vlan switch for Section.interfaces()
Sometimes we are only interested in the parent interfaces without any VLAN
subinterfaces. Extend the API with a vlan argument that defaults to True to
keep the current behavior in place.
-rw-r--r-- | python/vyos/ifconfig/section.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/python/vyos/ifconfig/section.py b/python/vyos/ifconfig/section.py index 91f667b65..5e98cd510 100644 --- a/python/vyos/ifconfig/section.py +++ b/python/vyos/ifconfig/section.py @@ -88,7 +88,7 @@ class Section: raise ValueError(f'No type found for interface name: {name}') @classmethod - def _intf_under_section (cls,section=''): + def _intf_under_section (cls,section='',vlan=True): """ return a generator with the name of the configured interface which are under a section @@ -103,6 +103,9 @@ class Section: if section and ifsection != section: continue + if vlan == False and '.' in ifname: + continue + yield ifname @classmethod @@ -135,13 +138,14 @@ class Section: return l @classmethod - def interfaces(cls, section=''): + def interfaces(cls, section='', vlan=True): """ return a list of the name of the configured interface which are under a section - if no section is provided, then it returns all configured interfaces + if no section is provided, then it returns all configured interfaces. + If vlan is True, also Vlan subinterfaces will be returned """ - return cls._sort_interfaces(cls._intf_under_section(section)) + return cls._sort_interfaces(cls._intf_under_section(section, vlan)) @classmethod def _intf_with_feature(cls, feature=''): |