Skip to content
Closed
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{# Auto-generated NDFC DC VXLAN EVPN VRFs config data structure for fabric {{ vxlan.fabric.name }} #}
{# Auto-generated NDFC DC VXLAN EVPN Networks config data structure for fabric {{ vxlan.fabric.name }} #}
{% set networks = [] %}
{% if data_model_extended.vxlan.overlay.networks is defined and data_model_extended.vxlan.overlay.networks %}
{% set networks = data_model_extended.vxlan.overlay.networks %}
Expand Down Expand Up @@ -65,7 +65,16 @@
{% endif %}
{% for attach in network_attach_groups_dict[net['network_attach_group']] %}
- ip_address: {{ attach['mgmt_ip_address'] }}
{% if attach['ports'] is defined %}
{% if attach['networks'] is defined %}
{% for attached_net in attach['networks'] %}
{% if attached_net['name'] == net['name'] %}
{% if attached_net['freeform_config'] is defined %}
freeform_config: |-
{{ attached_net['freeform_config'] | cisco.nac_dc_vxlan.dedent | indent(8, true) }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}{% if attach['ports'] is defined %}
ports: {{ attach['ports'] }}
{% endif %}
{% if 'tors' in attach and attach['tors'] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
{% endif %}
{% for attach in network_attach_groups_dict[net['network_attach_group']] %}
- ip_address: {{ attach['mgmt_ip_address'] }}
{% if attach['networks'] is defined %}
{% for attached_net in attach['networks'] %}
{% if attached_net['name'] == net['name'] %}
{% if attached_net['freeform_config'] is defined %}
freeform_config: |-
{{ attached_net['freeform_config'] | cisco.nac_dc_vxlan.dedent | indent(8, true) }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% if attach['ports'] is defined %}
ports: {{ attach['ports'] }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
{% endif %}
{% for attach in network_attach_groups_dict[net['network_attach_group']] %}
- ip_address: {{ attach['mgmt_ip_address'] }}
{% if attach['networks'] is defined %}
{% for attached_net in attach['networks'] %}
{% if attached_net['name'] == net['name'] %}
{% if attached_net['freeform_config'] is defined %}
freeform_config: |-
{{ attached_net['freeform_config'] | cisco.nac_dc_vxlan.dedent | indent(8, true) }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% if attach['ports'] is defined %}
ports: {{ attach['ports'] }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def match(cls, data_model):
if sm_networks and network_attach_groups:
results = cls.cross_reference_switches(network_attach_groups, switches, 'network', results)
results = cls.cross_reference_vpc_peers(network_attach_groups, vpc_peers, 'network', results)
results = cls.cross_reference_attached_networks(network_attach_groups, sm_networks, 'network', results)

return results

Expand Down Expand Up @@ -179,3 +180,34 @@ def cross_reference_vpc_peers(cls, attach_groups, vpc_peers, target, results):
)

return results

@classmethod
def cross_reference_attached_networks(cls, network_attach_groups, networks, target, results):
"""
Check if each network defined under the network_attach_group exists.
"""

if not network_attach_groups:
return results

for attach_group in network_attach_groups:
group_name = attach_group.get('name')
group_switches = attach_group.get('switches', [])
networks_name = [net['name'] for net in networks]

for switch in group_switches:
hostname = switch.get('hostname')
attached_networks = switch.get('networks')

if attached_networks:
for network in attached_networks:
attached_network_name = network.get('name')
if attached_network_name not in networks_name:
results.append(
f"{target}_attach_group '{group_name}' contains switch '{hostname}' "
f"which defines a network '{attached_network_name}', but the network "
f"is not defined in the service model. Add the Network to the service "
f"model and re-run the playbook."
)

return results
Loading