summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig_vlan.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-07-01 19:06:52 +0200
committerChristian Poessinger <christian@poessinger.com>2020-07-25 15:35:33 +0200
commitebefa38b9fa946fde82a4c9b55122c037598143b (patch)
tree8090cf3bb0401f445335e930d4643fbe6e3d4a00 /python/vyos/ifconfig_vlan.py
parent6d2ffb9badcd15d431b8bbb6b28d2171d06e6dc4 (diff)
downloadvyos-1x-ebefa38b9fa946fde82a4c9b55122c037598143b.tar.gz
vyos-1x-ebefa38b9fa946fde82a4c9b55122c037598143b.zip
ethernet: ifconfig: T2653: move to get_config_dict()
The current VyOS CLI parser code written in Python contains a ton of duplicates which I can also hold myself accountable for - or maybe mainly me - depends on the angle of judge. While providing a new update() method in vyos.ifconfig.interfaces() this is extended for ethernet based interfaces which also supports 802.1q, 802.1ad VLANs. This commit migrates the existing codebase for an ethernet based interfaces and implements the missing parts for VLANs. Adding or migrating other interfaces (e.g. bridge or bond) will become much easier as they must reuse the entire functionality - we now walk towards a single codepath. Thanks for all who made this combined effort possible! Signed-off-by: Christian Poessinger <christian@poessinger.com>
Diffstat (limited to 'python/vyos/ifconfig_vlan.py')
-rw-r--r--python/vyos/ifconfig_vlan.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/python/vyos/ifconfig_vlan.py b/python/vyos/ifconfig_vlan.py
index 442cb0db8..ecb6796fa 100644
--- a/python/vyos/ifconfig_vlan.py
+++ b/python/vyos/ifconfig_vlan.py
@@ -16,6 +16,30 @@
from netifaces import interfaces
from vyos import ConfigError
+def get_removed_vlans(conf, dict):
+ """
+ Common function to parse a dictionary retrieved via get_config_dict() and
+ determine any added/removed VLAN interfaces - be it 802.1q or Q-in-Q.
+ """
+ from vyos.configdiff import get_config_diff, Diff
+
+ # Check vif, vif-s/vif-c VLAN interfaces for removal
+ D = get_config_diff(conf, key_mangling=('-', '_'))
+ D.set_level(conf.get_level())
+ # get_child_nodes() will return dict_keys(), mangle this into a list with PEP448
+ keys = D.get_child_nodes_diff(['vif'], expand_nodes=Diff.DELETE)['delete'].keys()
+ dict['vif_remove'] = [*keys]
+
+ # get_child_nodes() will return dict_keys(), mangle this into a list with PEP448
+ keys = D.get_child_nodes_diff(['vif-s'], expand_nodes=Diff.DELETE)['delete'].keys()
+ dict['vif_s_remove'] = [*keys]
+
+ for vif in dict.get('vif_s', {}).keys():
+ keys = D.get_child_nodes_diff(['vif-s', vif, 'vif-c'], expand_nodes=Diff.DELETE)['delete'].keys()
+ dict['vif_s'][vif]['vif_c_remove'] = [*keys]
+
+ return dict
+
def apply_all_vlans(intf, intfconfig):
"""
Function applies all VLANs to the passed interface.