summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig_vlan.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/ifconfig_vlan.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/ifconfig_vlan.py')
-rw-r--r--python/vyos/ifconfig_vlan.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/python/vyos/ifconfig_vlan.py b/python/vyos/ifconfig_vlan.py
index eb7a369ec..54736ec6f 100644
--- a/python/vyos/ifconfig_vlan.py
+++ b/python/vyos/ifconfig_vlan.py
@@ -104,7 +104,8 @@ def verify_vlan_config(config):
implementing this function in multiple places use single source \o/
"""
- for vif in config['vif']:
+ # config['vif'] is a dict with ids as keys and config dicts as values
+ for vif in config['vif'].values():
# DHCPv6 parameters-only and temporary address are mutually exclusive
if vif['dhcpv6_prm_only'] and vif['dhcpv6_temporary']:
raise ConfigError('DHCPv6 temporary and parameters-only options are mutually exclusive!')
@@ -131,14 +132,19 @@ def verify_vlan_config(config):
if 'vif_s' not in config.keys():
return
- for vif_s in config['vif_s']:
- for vif in config['vif']:
- if vif['id'] == vif_s['id']:
- raise ConfigError('Can not use identical ID on vif and vif-s interface')
+ # config['vif_s'] is a dict with ids as keys and config dicts as values
+ for vif_s_id, vif_s in config['vif_s'].items():
+ for vif_id, vif in config['vif'].items():
+ if vif_id == vif_s_id:
+ raise ConfigError((
+ f'Cannot use identical ID on vif "{vif["intf"]}" '
+ f'and vif-s "{vif_s}"'))
# DHCPv6 parameters-only and temporary address are mutually exclusive
if vif_s['dhcpv6_prm_only'] and vif_s['dhcpv6_temporary']:
- raise ConfigError('DHCPv6 temporary and parameters-only options are mutually exclusive!')
+ raise ConfigError((
+ 'DHCPv6 temporary and parameters-only options are mutually '
+ 'exclusive!'))
if ( vif_s['is_bridge_member']
and ( vif_s['address']
@@ -157,10 +163,13 @@ def verify_vlan_config(config):
f'vif-s {vif_s["intf"]} cannot be member of VRF {vif_s["vrf"]} '
f'and bridge {vif_s["is_bridge_member"]} at the same time!'))
- for vif_c in vif_s['vif_c']:
+ # vif_c is a dict with ids as keys and config dicts as values
+ for vif_c in vif_s['vif_c'].values():
# DHCPv6 parameters-only and temporary address are mutually exclusive
if vif_c['dhcpv6_prm_only'] and vif_c['dhcpv6_temporary']:
- raise ConfigError('DHCPv6 temporary and parameters-only options are mutually exclusive!')
+ raise ConfigError((
+ 'DHCPv6 temporary and parameters-only options are '
+ 'mutually exclusive!'))
if ( vif_c['is_bridge_member']
and ( vif_c['address']