[minigraph]: Add portchannels/vlans dictionary and update teamd templates (#408)

- minigraph_portchannel_interfaces and minigraph_vlan_interfaces are lists
  of interfaces and the name could duplicate due to multiple IPs
- Add minigraph_portchannels and minigraph_vlans dictionaries to support
  querying port channels and vlans via the name
- Update teamd.j2 template and config.sh file in docker-teamd
- Update zebra.conf.j2 template to add port channel interfaces

Signed-off-by: Shuotian Cheng <shuche@microsoft.com>
This commit is contained in:
Shuotian Cheng 2017-03-17 16:48:13 -07:00 committed by GitHub
parent 3643281594
commit 783be14a5d
4 changed files with 18 additions and 5 deletions

View File

@ -19,6 +19,11 @@ interface {{ interface['alias'] }}
link-detect
!
{% endfor %}
{% for interface in minigraph_portchannel_interfaces %}
interface {{ interface['name'] }}
link-detect
!
{% endfor %}
{% endblock interfaces %}
!
{% block default_route %}

View File

@ -2,7 +2,7 @@
mkdir -p /etc/teamd
for pc in `sonic-cfggen -m /etc/sonic/minigraph.xml -v "' '.join(minigraph_portchannel_interfaces.keys())"`; do
for pc in `sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_portchannels.keys() | join(' ')"`; do
sonic-cfggen -m /etc/sonic/minigraph.xml -a '{"pc":"'$pc'"}' -t /usr/share/sonic/templates/teamd.j2 >/etc/teamd/$pc.conf
done

View File

@ -4,14 +4,14 @@
"name": "lacp",
"active": true,
{# Use 75% links upperbound as min-links #}
"min_ports": {{ minigraph_portchannel_interfaces[pc] | length * 0.75 | round(0, 'ceil') | int}},
"min_ports": {{ minigraph_portchannels[pc]['members'] | length * 0.75 | round(0, 'ceil') | int}},
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
{% for member in minigraph_portchannel_interfaces[pc] %}
{% for member in minigraph_portchannels[pc]['members'] %}
"{{member}}": {}{% if not loop.last %},{% endif %}
{% endfor %}

View File

@ -180,6 +180,7 @@ def parse_dpg(dpg, hname):
pcintfs = child.find(str(QName(ns, "PortChannelInterfaces")))
pc_intfs = []
pcs = {}
for pcintf in pcintfs.findall(str(QName(ns, "PortChannel"))):
pcintfname = pcintf.find(str(QName(ns, "Name"))).text
pcintfmbr = pcintf.find(str(QName(ns, "AttachTo"))).text
@ -191,6 +192,7 @@ def parse_dpg(dpg, hname):
for addrtuple in pc_map.get(pcintfname, []):
pc_attributes.update(addrtuple)
pc_intfs.append(copy.deepcopy(pc_attributes))
pcs[pcintfname] = pc_attributes
lointfs = child.find(str(QName(ns, "LoopbackIPInterfaces")))
lo_intfs = []
@ -221,6 +223,7 @@ def parse_dpg(dpg, hname):
vlanintfs = child.find(str(QName(ns, "VlanInterfaces")))
vlan_intfs = []
vlans = {}
for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))):
vintfname = vintf.find(str(QName(ns, "Name"))).text
vlanid = vintf.find(str(QName(ns, "VlanID"))).text
@ -233,9 +236,10 @@ def parse_dpg(dpg, hname):
for addrtuple in vlan_map.get(vintfname, []):
vlan_attributes.update(addrtuple)
vlan_intfs.append(copy.deepcopy(vlan_attributes))
vlans[vintfname] = vlan_attributes
return intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs
return intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs, vlans, pcs
return None, None, None, None, None
def parse_cpg(cpg, hname):
@ -362,6 +366,8 @@ def parse_xml(filename, platform=None):
intfs = None
vlan_intfs = None
pc_intfs = None
vlans = None
pcs = None
mgmt_intf = None
lo_intf = None
neighbors = None
@ -386,7 +392,7 @@ def parse_xml(filename, platform=None):
for child in root:
if child.tag == str(QName(ns, "DpgDec")):
(intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs) = parse_dpg(child, hostname)
(intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs, vlans, pcs) = parse_dpg(child, hostname)
elif child.tag == str(QName(ns, "CpgDec")):
(bgp_sessions, bgp_asn) = parse_cpg(child, hostname)
elif child.tag == str(QName(ns, "PngDec")):
@ -409,6 +415,8 @@ def parse_xml(filename, platform=None):
results['minigraph_interfaces'] = sorted(intfs, key=lambda x: x['name'])
results['minigraph_vlan_interfaces'] = vlan_intfs
results['minigraph_portchannel_interfaces'] = pc_intfs
results['minigraph_vlans'] = vlans
results['minigraph_portchannels'] = pcs
results['minigraph_mgmt_interface'] = mgmt_intf
results['minigraph_lo_interfaces'] = lo_intfs
results['minigraph_neighbors'] = neighbors