Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dualtor][minigraph] Add SoC addr minigraph support #5614

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ansible/library/dual_tor_facts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
import os
import yaml

from collections import defaultdict

try:
from ansible.module_utils.dualtor_utils import generate_mux_cable_facts
except ImportError:
# Add parent dir for using outside Ansible
import sys
sys.path.append('..')
from ansible.module_utils.dualtor_utils import generate_mux_cable_facts


def load_topo_file(topo_name):
"""Load topo definition yaml file."""
topo_file = "vars/topo_%s.yml" % topo_name
if not os.path.exists(topo_file):
raise ValueError("Topo file %s not exists" % topo_file)
with open(topo_file) as fd:
return yaml.safe_load(fd)


class DualTorParser:

def __init__(self, hostname, testbed_facts, host_vars, vm_config, port_alias, vlan_intfs):
Expand Down Expand Up @@ -64,6 +86,14 @@ def generate_cable_names(self):

self.dual_tor_facts['cables'] = cables

def generate_mux_cable_facts(self):
topo_name = self.testbed_facts["topo"]
# use mux_cable_facts only for dualtor mixed topologies
if "mixed" in topo_name:
topology = load_topo_file(topo_name)["topology"]
mux_cable_facts = generate_mux_cable_facts(topology=topology)
self.dual_tor_facts["mux_cable_facts"] = mux_cable_facts

def get_dual_tor_facts(self):
'''
Gathers facts related to a dual ToR configuration
Expand All @@ -73,6 +103,7 @@ def get_dual_tor_facts(self):
self.parse_tor_position()
self.generate_cable_names()
self.parse_loopback_ips()
self.generate_mux_cable_facts()

return self.dual_tor_facts

Expand Down
20 changes: 19 additions & 1 deletion ansible/templates/minigraph_png.j2
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,21 @@
{% set server_base_address_v6 = (vlan_configs.values() | list)[0]['prefix_v6'] %}
{% set server_base_address_v6 = server_base_address_v6 | ipaddr('network') %}
{% set server_base_address_v6 = ':'.join(server_base_address_v6.split(':')[:-1]) + ':{:x}' %}
{% set mux_cable_facts = dual_tor_facts['mux_cable_facts'] if 'mux_cable_facts' in dual_tor_facts %}
{% for cable in dual_tor_facts['cables'] %}
{% set intf_index = port_alias.index(cable['dut_intf'])|string %}
<Device i:type="SmartCable">
<ElementType>SmartCable</ElementType>
{% if mux_cable_facts is defined %}
<SubType>{{ mux_cable_facts[intf_index]['cable_type'] }}</SubType>
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ mux_cable_facts[intf_index]['soc_ipv4'] if 'soc_ipv4' in mux_cable_facts[intf_index] else '0.0.0.0/0' }}</d5p1:IPPrefix>
</Address>
{% else %}
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
</Address>
{% endif %}
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>::/0</d5p1:IPPrefix>
</AddressV6>
Expand All @@ -159,12 +168,21 @@
</Device>
<Device i:type="Server">
<ElementType>Server</ElementType>
{% if mux_cable_facts is defined %}
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ mux_cable_facts[intf_index]['server_ipv4'] }}</d5p1:IPPrefix>
</Address>
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ mux_cable_facts[intf_index]['server_ipv6'] }}</d5p1:IPPrefix>
</AddressV6>
{% else %}
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ server_base_address_v4.format(loop.index + 1) }}/26</d5p1:IPPrefix>
</Address>
</Address>
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ server_base_address_v6.format(loop.index + 1) }}/96</d5p1:IPPrefix>
</AddressV6>
{% endif %}
<ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
</ManagementAddress>
Expand Down