Skip to content

Commit

Permalink
WIP: Support old style VLAN config
Browse files Browse the repository at this point in the history
  • Loading branch information
cosandr committed Sep 18, 2023
1 parent d098c20 commit 5bba138
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
83 changes: 82 additions & 1 deletion plugins/module_utils/_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, primary_keys=None,
unknown_mechanism=False,
fully_understood=False,
fixed_entries=False,
fallback_single_value=False,
fields=None):
if sum([primary_keys is not None, stratify_keys is not None, has_identifier, single_value, unknown_mechanism]) > 1:
raise ValueError('primary_keys, stratify_keys, has_identifier, single_value, and unknown_mechanism are mutually exclusive')
Expand All @@ -34,6 +35,7 @@ def __init__(self, primary_keys=None,
self.unknown_mechanism = unknown_mechanism
self.fully_understood = fully_understood
self.fixed_entries = fixed_entries
self.fallback_single_value = fallback_single_value
if fixed_entries and primary_keys is None:
raise ValueError('fixed_entries can only be used with primary_keys')
if fields is None:
Expand Down Expand Up @@ -2591,12 +2593,43 @@ def join_path(path):
('interface', 'ethernet', 'switch'): APIData(
fixed_entries=True,
primary_keys=('name', ),
fallback_single_value=True,
fully_understood=True,
fields={
'name': KeyInfo(),
# CRS3xx
'cpu-flow-control': KeyInfo(default=True),
'l3-hw-offloading': KeyInfo(default=False),
'mirror-egress-target': KeyInfo(default='none'),
'mirror-source': KeyInfo(default='none'),
'mirror-target': KeyInfo(default='none'),
'name': KeyInfo(),
# CRS1xx/2xx
'bridge-type': KeyInfo(default='customer-vid-used-as-lookup-vid'),
'bypass-ingress-port-policing-for': KeyInfo(default=''),
'bypass-l2-security-check-filter-for': KeyInfo(default=''),
'bypass-vlan-ingress-filter-for': KeyInfo(default=''),
'drop-if-invalid-or-src-port-not-member-of-vlan-on-ports': KeyInfo(default=''),
'drop-if-no-vlan-assignment-on-ports': KeyInfo(default=''),
'egress-mirror-ratio': KeyInfo(default='1/1'),
'egress-mirror0': KeyInfo(default='switch1-cpu,modified'),
'egress-mirror1': KeyInfo(default='switch1-cpu,modified'),
'fdb-uses': KeyInfo(default='mirror0'),
'forward-unknown-vlan': KeyInfo(default=True),
'ingress-mirror-ratio': KeyInfo(default='1/1'),
'ingress-mirror0': KeyInfo(default='switch1-cpu,unmodified'),
'ingress-mirror1': KeyInfo(default='switch1-cpu,unmodified'),
'mac-level-isolation': KeyInfo(default=True),
'mirror-egress-if-ingress-mirrored': KeyInfo(default=False),
'mirror-tx-on-mirror-port': KeyInfo(default=False),
'mirrored-packet-drop-precedence': KeyInfo(default='green'),
'mirrored-packet-qos-priority': KeyInfo(default=0),
'multicast-lookup-mode': KeyInfo(default='dst-ip-and-vid-for-ipv4'),
'override-existing-when-ufdb-full': KeyInfo(default=False),
'unicast-fdb-timeout': KeyInfo(default='5m'),
'unknown-vlan-lookup-mode': KeyInfo(default='svl'),
'use-cvid-in-one2one-vlan-lookup': KeyInfo(default=True),
'use-svid-in-one2one-vlan-lookup': KeyInfo(default=False),
'vlan-uses': KeyInfo(default='mirror0'),
},
),
('interface', 'ethernet', 'switch', 'port'): APIData(
Expand All @@ -2610,6 +2643,54 @@ def join_path(path):
'vlan-mode': KeyInfo(default='disabled'),
},
),
('interface', 'ethernet', 'switch', 'vlan'): APIData(
fully_understood=True,
# primary_keys=('ports', 'vlan-id', ),
primary_keys=('vlan-id', ),
fields={
'comment': KeyInfo(can_disable=True, remove_value=''),
'disabled': KeyInfo(default=False),
'flood': KeyInfo(default=False),
'ingress-mirror': KeyInfo(default=False),
'learn': KeyInfo(default=True),
'ports': KeyInfo(),
'qos-group': KeyInfo(default='none'),
'svl': KeyInfo(default=False),
'vlan-id': KeyInfo(),
},
),
('interface', 'ethernet', 'switch', 'ingress-vlan-translation'): APIData(
fully_understood=True,
primary_keys=('ports', ),
fields={
'customer-dei': KeyInfo(),
'customer-pcp': KeyInfo(),
'customer-vid': KeyInfo(),
'customer-vlan-format': KeyInfo(default='any'),
'disabled': KeyInfo(default=False),
'new-customer-vid': KeyInfo(),
'new-service-vid': KeyInfo(),
'pcp-propagation': KeyInfo(default=False),
'ports': KeyInfo(),
'protocol': KeyInfo(),
'sa-learning': KeyInfo(default=True),
'service-dei': KeyInfo(),
'service-pcp': KeyInfo(),
'service-vid': KeyInfo(),
'service-vlan-format': KeyInfo(default='any'),
'swap-vids': KeyInfo(),
},
),
('interface', 'ethernet', 'switch', 'egress-vlan-tag'): APIData(
primary_keys=('vlan-id', ),
fully_understood=True,
fields={
'comment': KeyInfo(can_disable=True, remove_value=''),
'disabled': KeyInfo(default=False),
'tagged-ports': KeyInfo(),
'vlan-id': KeyInfo(),
},
),
('ip', 'dhcp-client', 'option'): APIData(
fixed_entries=True,
primary_keys=('name', ),
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- interface ethernet
- interface ethernet poe
- interface ethernet switch
- interface ethernet switch egress-vlan-tag
- interface ethernet switch port
- interface gre
- interface gre6
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/api_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
- interface ethernet
- interface ethernet poe
- interface ethernet switch
- interface ethernet switch egress-vlan-tag
- interface ethernet switch port
- interface gre
- interface gre6
Expand Down Expand Up @@ -770,6 +771,9 @@ def sync_with_primary_keys(module, api, path, path_info):

old_data = get_api_data(api_path, path_info)
old_data = remove_dynamic(old_data)
# CRS1xx/2xx workaround, unlikely to work on devices with more than one switch chip
if path_info.fallback_single_value and len(old_data) == 1 and '.id' not in old_data[0]:
return sync_single_value(module, api, path, path_info)
old_data_by_key = OrderedDict()
id_by_key = {}
for entry in old_data:
Expand Down

0 comments on commit 5bba138

Please sign in to comment.