diff --git a/plugins/action/dtc/manage_child_fabric_networks.py b/plugins/action/dtc/manage_child_fabric_networks.py index 83f1966a2..1df268da7 100644 --- a/plugins/action/dtc/manage_child_fabric_networks.py +++ b/plugins/action/dtc/manage_child_fabric_networks.py @@ -43,6 +43,7 @@ # Currently supported Network template config keys and their mapping to data model keys NETWORK_TEMPLATE_CONFIG_MAP = { 'loopbackId': {'dm_key': 'dhcp_loopback_id', 'default': ''}, + 'dhcpServers': {'dm_key': 'dhcp_servers', 'default': ''}, 'ENABLE_NETFLOW': {'dm_key': 'netflow_enable', 'default': False}, 'VLAN_NETFLOW_MONITOR': {'dm_key': 'vlan_netflow_monitor', 'default': ''}, 'trmEnabled': {'dm_key': 'trm_enable', 'default': False}, diff --git a/roles/dtc/common/templates/ndfc_networks/dc_vxlan_fabric/dc_vxlan_fabric_networks.j2 b/roles/dtc/common/templates/ndfc_networks/dc_vxlan_fabric/dc_vxlan_fabric_networks.j2 index 5789559d6..71e244229 100644 --- a/roles/dtc/common/templates/ndfc_networks/dc_vxlan_fabric/dc_vxlan_fabric_networks.j2 +++ b/roles/dtc/common/templates/ndfc_networks/dc_vxlan_fabric/dc_vxlan_fabric_networks.j2 @@ -33,23 +33,12 @@ {% endif %} arp_suppress: {{ net['arp_suppress'] | default(defaults.vxlan.overlay.networks.arp_supress) }} dhcp_loopback_id: {{ net['dhcp_loopback_id'] | default(omit) }} -{% if net.dhcp_servers is defined %} -{% if net.dhcp_servers | length == 1 %} - dhcp_srvr1_ip: {{ net['dhcp_servers'][0]['ip_address'] }} - dhcp_srvr1_vrf: {{ net['dhcp_servers'][0]['vrf'] }} -{% elif net.dhcp_servers | length == 2 %} - dhcp_srvr1_ip: {{ net['dhcp_servers'][0]['ip_address'] }} - dhcp_srvr1_vrf: {{ net['dhcp_servers'][0]['vrf'] }} - dhcp_srvr2_ip: {{ net['dhcp_servers'][1]['ip_address'] }} - dhcp_srvr2_vrf: {{ net['dhcp_servers'][1]['vrf'] }} -{% elif net.dhcp_servers | length == 3 %} - dhcp_srvr1_ip: {{ net['dhcp_servers'][0]['ip_address'] }} - dhcp_srvr1_vrf: {{ net['dhcp_servers'][0]['vrf'] }} - dhcp_srvr2_ip: {{ net['dhcp_servers'][1]['ip_address'] }} - dhcp_srvr2_vrf: {{ net['dhcp_servers'][1]['vrf'] }} - dhcp_srvr3_ip: {{ net['dhcp_servers'][2]['ip_address'] }} - dhcp_srvr3_vrf: {{ net['dhcp_servers'][2]['vrf'] }} -{% endif %} +{% if net.dhcp_servers is defined and net.dhcp_servers %} + dhcp_servers: +{% for dhcp_server in net.dhcp_servers %} + - srvr_ip: {{ dhcp_server['ip_address'] }} + srvr_vrf: {{ dhcp_server['vrf'] }} +{% endfor %} {% endif %} gw_ipv6_subnet: {{ net['gw_ipv6_address'] | default(omit) }} int_desc: {{ net['int_desc'] | default(defaults.vxlan.overlay.networks.net_description) }} diff --git a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.1/msd_child_fabric_network.j2 b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.1/msd_child_fabric_network.j2 index 269d89ad7..07a86a5c8 100644 --- a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.1/msd_child_fabric_network.j2 +++ b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.1/msd_child_fabric_network.j2 @@ -1,4 +1,14 @@ {# Auto-generated NDFC VXLAN EVPN MSD Child Fabric Network config data structure for fabric {{ fabric_name }} #} +{%- set _dhcp_pairs = [] -%} +{%- if dm['dhcp_servers'] is defined and dm['dhcp_servers'] -%} +{%- for srvr in dm['dhcp_servers'] -%} +{%- set _ = _dhcp_pairs.append({ + "srvrAddr": srvr['ip_address'], "srvrVrf": srvr['vrf'] | default("") +}) -%} +{%- endfor -%} +{%- endif -%} +{%- set _dhcp_obj = {'dhcpServers': _dhcp_pairs} -%} +{%- set dhcpServers = _dhcp_obj if (_dhcp_pairs|length > 0) else '' -%} { "fabric": "{{ fabric_name }}", "networkName": "{{ network_name }}", @@ -24,12 +34,7 @@ "secondaryGW3": ndfc.secondaryGW3, "secondaryGW4": ndfc.secondaryGW4, "loopbackId": dm.dhcp_loopback_id | default(ndfc.loopbackId), - "dhcpServerAddr1": dm['dhcp_servers'][0]['ip_address'] if dm['dhcp_servers'][0]['ip_address'] is defined else "", - "vrfDhcp": dm['dhcp_servers'][0]['vrf'] if dm['dhcp_servers'][0]['ip_address'] is defined else ndfc.vrfDhcp, - "dhcpServerAddr2": dm['dhcp_servers'][1]['ip_address'] if dm['dhcp_servers'][1]['ip_address'] is defined else ndfc.dhcpServerAddr2, - "vrfDhcp2": dm['dhcp_servers'][1]['vrf'] if dm['dhcp_servers'][1]['ip_address'] is defined else "", - "dhcpServerAddr3": dm['dhcp_servers'][2]['ip_address'] if dm['dhcp_servers'][2]['ip_address'] is defined else ndfc.dhcpServerAddr3, - "vrfDhcp3": dm['dhcp_servers'][2]['vrf'] if dm['dhcp_servers'][2]['vrf'] is defined else "", + "dhcpServers": dhcpServers, "ENABLE_NETFLOW": dm.netflow_enable if dm.netflow_enable is defined else ndfc.ENABLE_NETFLOW, "SVI_NETFLOW_MONITOR": ndfc.SVI_NETFLOW_MONITOR, "VLAN_NETFLOW_MONITOR": dm.vlan_netflow_monitor if (dm.netflow_enable is defined and dm.netflow_enable) else ndfc.VLAN_NETFLOW_MONITOR, diff --git a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.2/msd_child_fabric_network.j2 b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.2/msd_child_fabric_network.j2 index f48e4a0b7..750f0764f 100644 --- a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.2/msd_child_fabric_network.j2 +++ b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/3.2/msd_child_fabric_network.j2 @@ -1,4 +1,14 @@ {# Auto-generated NDFC VXLAN EVPN MSD Child Fabric Network config data structure for fabric {{ fabric_name }} #} +{%- set _dhcp_pairs = [] -%} +{%- if dm['dhcp_servers'] is defined and dm['dhcp_servers'] -%} +{%- for srvr in dm['dhcp_servers'] -%} +{%- set _ = _dhcp_pairs.append({ + "srvrAddr": srvr['ip_address'], "srvrVrf": srvr['vrf'] | default("") +}) -%} +{%- endfor -%} +{%- endif -%} +{%- set _dhcp_obj = {'dhcpServers': _dhcp_pairs} -%} +{%- set dhcpServers = _dhcp_obj if (_dhcp_pairs|length > 0) else '' -%} { "fabric": "{{ fabric_name }}", "networkName": "{{ network_name }}", @@ -24,12 +34,7 @@ "secondaryGW3": ndfc.secondaryGW3, "secondaryGW4": ndfc.secondaryGW4, "loopbackId": dm.dhcp_loopback_id | default(ndfc.loopbackId), - "dhcpServerAddr1": dm['dhcp_servers'][0]['ip_address'] if dm['dhcp_servers'][0]['ip_address'] is defined else "", - "vrfDhcp": dm['dhcp_servers'][0]['vrf'] if dm['dhcp_servers'][0]['ip_address'] is defined else ndfc.vrfDhcp, - "dhcpServerAddr2": dm['dhcp_servers'][1]['ip_address'] if dm['dhcp_servers'][1]['ip_address'] is defined else ndfc.dhcpServerAddr2, - "vrfDhcp2": dm['dhcp_servers'][1]['vrf'] if dm['dhcp_servers'][1]['ip_address'] is defined else "", - "dhcpServerAddr3": dm['dhcp_servers'][2]['ip_address'] if dm['dhcp_servers'][2]['ip_address'] is defined else ndfc.dhcpServerAddr3, - "vrfDhcp3": dm['dhcp_servers'][2]['vrf'] if dm['dhcp_servers'][2]['vrf'] is defined else "", + "dhcpServers": dhcpServers, "ENABLE_NETFLOW": dm.netflow_enable if dm.netflow_enable is defined else ndfc.ENABLE_NETFLOW, "SVI_NETFLOW_MONITOR": ndfc.SVI_NETFLOW_MONITOR, "VLAN_NETFLOW_MONITOR": dm.vlan_netflow_monitor if (dm.netflow_enable is defined and dm.netflow_enable) else ndfc.VLAN_NETFLOW_MONITOR, diff --git a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/4.1/msd_child_fabric_network.j2 b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/4.1/msd_child_fabric_network.j2 index d8687a95f..1e0daa3b0 100644 --- a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/4.1/msd_child_fabric_network.j2 +++ b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/4.1/msd_child_fabric_network.j2 @@ -1,4 +1,17 @@ {# Auto-generated NDFC VXLAN EVPN MSD Child Fabric Network config data structure for fabric {{ fabric_name }} #} +{# Build dhcpServers as a JSON dict (or empty string) #} +{%- set _dhcp_pairs = [] -%} +{%- if dm is defined and dm['dhcp_servers'] is defined and dm['dhcp_servers'] -%} + {%- for srvr in dm['dhcp_servers'] -%} + {%- if srvr['ip_address'] is defined and srvr['ip_address'] -%} + {%- set _ = _dhcp_pairs.append({ + "srvrAddr": srvr['ip_address'], "srvrVrf": srvr['vrf'] + }) -%} + {%- endif -%} + {%- endfor -%} +{%- endif -%} +{%- set _dhcp_obj = {'dhcpServers': _dhcp_pairs} -%} +{%- set dhcpServers = _dhcp_obj if (_dhcp_pairs|length > 0) else '' -%} { "fabric": "{{ fabric_name }}", "networkName": "{{ network_name }}", @@ -24,12 +37,7 @@ "secondaryGW3": ndfc.secondaryGW3, "secondaryGW4": ndfc.secondaryGW4, "loopbackId": dm.dhcp_loopback_id | default(ndfc.loopbackId), - "dhcpServerAddr1": dm['dhcp_servers'][0]['ip_address'] if dm['dhcp_servers'][0]['ip_address'] is defined else "", - "vrfDhcp": dm['dhcp_servers'][0]['vrf'] if dm['dhcp_servers'][0]['ip_address'] is defined else ndfc.vrfDhcp, - "dhcpServerAddr2": dm['dhcp_servers'][1]['ip_address'] if dm['dhcp_servers'][1]['ip_address'] is defined else ndfc.dhcpServerAddr2, - "vrfDhcp2": dm['dhcp_servers'][1]['vrf'] if dm['dhcp_servers'][1]['ip_address'] is defined else "", - "dhcpServerAddr3": dm['dhcp_servers'][2]['ip_address'] if dm['dhcp_servers'][2]['ip_address'] is defined else ndfc.dhcpServerAddr3, - "vrfDhcp3": dm['dhcp_servers'][2]['vrf'] if dm['dhcp_servers'][2]['vrf'] is defined else "", + "dhcpServers": dhcpServers, "ENABLE_NETFLOW": dm.netflow_enable if dm.netflow_enable is defined else ndfc.ENABLE_NETFLOW, "SVI_NETFLOW_MONITOR": ndfc.SVI_NETFLOW_MONITOR, "VLAN_NETFLOW_MONITOR": dm.vlan_netflow_monitor if (dm.netflow_enable is defined and dm.netflow_enable) else ndfc.VLAN_NETFLOW_MONITOR, diff --git a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/msd_child_fabric_network.j2 b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/msd_child_fabric_network.j2 index f29208713..603384aea 100644 --- a/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/msd_child_fabric_network.j2 +++ b/roles/dtc/common/templates/ndfc_networks/msd_fabric/child_fabric/msd_child_fabric_network.j2 @@ -1,4 +1,14 @@ {# Auto-generated NDFC VXLAN EVPN MSD Child Fabric Network config data structure for fabric {{ fabric_name }} #} +{%- set _dhcp_pairs = [] -%} +{%- if dm['dhcp_servers'] is defined and dm['dhcp_servers'] -%} +{%- for srvr in dm['dhcp_servers'] -%} +{%- set _ = _dhcp_pairs.append({ + "srvrAddr": srvr['ip_address'], "srvrVrf": srvr['vrf'] | default("") +}) -%} +{%- endfor -%} +{%- endif -%} +{%- set _dhcp_obj = {'dhcpServers': _dhcp_pairs} -%} +{%- set dhcpServers = _dhcp_obj if (_dhcp_pairs|length > 0) else '' -%} { "fabric": "{{ fabric_name }}", "networkName": "{{ network_name }}", @@ -25,12 +35,7 @@ "secondaryGW3": ndfc.secondaryGW3, "secondaryGW4": ndfc.secondaryGW4, "loopbackId": dm.dhcp_loopback_id | default(ndfc.loopbackId), - "dhcpServerAddr1": dm['dhcp_servers'][0]['ip_address'] if dm['dhcp_servers'][0]['ip_address'] is defined else "", - "vrfDhcp": dm['dhcp_servers'][0]['vrf'] if dm['dhcp_servers'][0]['ip_address'] is defined else ndfc.vrfDhcp, - "dhcpServerAddr2": dm['dhcp_servers'][1]['ip_address'] if dm['dhcp_servers'][1]['ip_address'] is defined else ndfc.dhcpServerAddr2, - "vrfDhcp2": dm['dhcp_servers'][1]['vrf'] if dm['dhcp_servers'][1]['ip_address'] is defined else "", - "dhcpServerAddr3": dm['dhcp_servers'][2]['ip_address'] if dm['dhcp_servers'][2]['ip_address'] is defined else ndfc.dhcpServerAddr3, - "vrfDhcp3": dm['dhcp_servers'][2]['vrf'] if dm['dhcp_servers'][2]['vrf'] is defined else "", + "dhcpServers": dhcpServers, "ENABLE_NETFLOW": dm.netflow_enable if dm.netflow_enable is defined else ndfc.ENABLE_NETFLOW, "SVI_NETFLOW_MONITOR": ndfc.SVI_NETFLOW_MONITOR, "VLAN_NETFLOW_MONITOR": dm.vlan_netflow_monitor if (dm.netflow_enable is defined and dm.netflow_enable) else ndfc.VLAN_NETFLOW_MONITOR,