summaryrefslogtreecommitdiff
path: root/python/vyos/configdict.py
diff options
context:
space:
mode:
authorJernej Jakob <jernej.jakob@gmail.com>2020-05-05 15:57:31 +0200
committerJernej Jakob <jernej.jakob@gmail.com>2020-05-05 17:25:32 +0200
commit023b6b772ee6d6853e1c0e585b7f7d207e9926ce (patch)
treeb0e0fdf60fb1bda24d7f9a46b0cbe7b410e92cb5 /python/vyos/configdict.py
parent7a1c1fef7677e68d5a92c8538eda74a45b47a3c9 (diff)
downloadvyos-1x-023b6b772ee6d6853e1c0e585b7f7d207e9926ce.tar.gz
vyos-1x-023b6b772ee6d6853e1c0e585b7f7d207e9926ce.zip
vlan: T2427: convert vlan config variables from lists to dicts
Previously all vlan configs, which are dicts, were appended to a simple list, with the distinguishing 'id' stored inside the dicts themselves. This worked, but wasn't ideal. This commit converts them to dicts, where the key is the VLAN ID and value the config dict of that VLAN. This makes it posible to access single VLANs by their ID (key) and we can for-loop and get both the ID and config with: 'for vif_id, vif in conf["vif"].items():'
Diffstat (limited to 'python/vyos/configdict.py')
-rw-r--r--python/vyos/configdict.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py
index ceacf86fc..666497389 100644
--- a/python/vyos/configdict.py
+++ b/python/vyos/configdict.py
@@ -132,7 +132,7 @@ vlan_default = {
'is_bridge_member': False,
'mac': '',
'mtu': 1500,
- 'vif_c': [],
+ 'vif_c': {},
'vif_c_remove': [],
'vrf': ''
}
@@ -400,7 +400,8 @@ def add_to_dict(conf, disabled, ifdict, section, key):
for s in sections:
# set config level to vif interface
conf.set_level(current_level + [section, s])
- ifdict[f'{key}'].append(vlan_to_dict(conf))
+ # add the vlan config as a key (vlan id) - value (config) pair
+ ifdict[key][s] = vlan_to_dict(conf)
# re-set configuration level to leave things as found
conf.set_level(current_level)
@@ -411,12 +412,8 @@ def add_to_dict(conf, disabled, ifdict, section, key):
def vlan_to_dict(conf, default=vlan_default):
vlan, disabled = intf_to_dict(conf, default)
- level = conf.get_level()
- # get the '100' in 'interfaces bonding bond0 vif-s 100'
- vlan['id'] = level[-1]
-
# if this is a not within vif-s node, we are done
- if level[-2] != 'vif-s':
+ if conf.get_level()[-2] != 'vif-s':
return vlan
# ethertype is mandatory on vif-s nodes and only exists here!
@@ -428,7 +425,6 @@ def vlan_to_dict(conf, default=vlan_default):
# check if there is a Q-in-Q vlan customer interface
# and call this function recursively
-
add_to_dict(conf, disable, vlan, 'vif-c', 'vif_c')
return vlan