diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-11 16:42:40 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-11 19:08:30 +0100 |
commit | 8bc12847568582d3b34f3859946470af1344f9ea (patch) | |
tree | c4dff573a8262022515247f802c667988e2d30a9 /python/vyos/ifconfig/section.py | |
parent | d3aa0bd68bb72bc35eb290b1c54cae4dfa4efb57 (diff) | |
download | vyos-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 'python/vyos/ifconfig/section.py')
-rw-r--r-- | python/vyos/ifconfig/section.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/python/vyos/ifconfig/section.py b/python/vyos/ifconfig/section.py index 4f76258a7..234c9a6cc 100644 --- a/python/vyos/ifconfig/section.py +++ b/python/vyos/ifconfig/section.py @@ -19,6 +19,7 @@ import netifaces class Section: # the known interface prefixes _prefixes = {} + _classes = [] # class need to define: definition['prefixes'] # the interface prefixes declared by a class used to name interface with @@ -34,6 +35,8 @@ class Section: if not klass.definition.get('prefixes',[]): raise RuntimeError(f'valid interface prefixes not defined for {klass.__name__}') + cls._classes.append(klass) + for ifprefix in klass.definition['prefixes']: if ifprefix in cls._prefixes: raise RuntimeError(f'only one class can be registered for prefix "{ifprefix}" type') @@ -110,6 +113,22 @@ class Section: """ return list(cls._intf_under_section(section)) + @classmethod + def _intf_with_feature(cls, feature=''): + """ + return a generator with the name of the interface which have + a particular feature set in their definition such as: + bondable, broadcast, bridgeable, ... + """ + for klass in cls._classes: + if klass.definition[feature]: + yield klass.definition['section'] -# XXX: TODO - limit name for VRF interfaces - + @classmethod + def feature(cls, feature=''): + """ + return list with the name of the interface which have + a particular feature set in their definition such as: + bondable, broadcast, bridgeable, ... + """ + return list(cls._intf_with_feature(feature)) |