summaryrefslogtreecommitdiff
path: root/python/vyos/configdict.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/configdict.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/configdict.py')
-rw-r--r--python/vyos/configdict.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py
index 0dc7578d8..682caed8f 100644
--- a/python/vyos/configdict.py
+++ b/python/vyos/configdict.py
@@ -102,12 +102,35 @@ def dict_merge(source, destination):
return tmp
def list_diff(first, second):
- """
- Diff two dictionaries and return only unique items
- """
+ """ Diff two dictionaries and return only unique items """
second = set(second)
return [item for item in first if item not in second]
+def T2665_default_dict_cleanup(dict):
+ """ Cleanup default keys for tag nodes https://phabricator.vyos.net/T2665. """
+ # Cleanup
+ for vif in ['vif', 'vif_s']:
+ if vif in dict.keys():
+ for key in ['ip', 'mtu']:
+ if key in dict[vif].keys():
+ del dict[vif][key]
+
+ # cleanup VIF-S defaults
+ if 'vif_c' in dict[vif].keys():
+ for key in ['ip', 'mtu']:
+ if key in dict[vif]['vif_c'].keys():
+ del dict[vif]['vif_c'][key]
+ # If there is no vif-c defined and we just cleaned the default
+ # keys - we can clean the entire vif-c dict as it's useless
+ if not dict[vif]['vif_c']:
+ del dict[vif]['vif_c']
+
+ # If there is no real vif/vif-s defined and we just cleaned the default
+ # keys - we can clean the entire vif dict as it's useless
+ if not dict[vif]:
+ del dict[vif]
+
+ return dict
def get_ethertype(ethertype_val):
if ethertype_val == '0x88A8':