Force LCP names to be unique

This commit is contained in:
Pim van Pelt
2022-03-13 13:17:14 +00:00
parent 2ced42e97a
commit 0313666f69
2 changed files with 26 additions and 0 deletions

View File

@ -15,6 +15,10 @@ interfaces:
101:
description: "Infra: L2 for FrysIX AS112"
GigabitEthernet1/0/1:
description: "Broken - has same LCP as above"
lcp: e0-1
GigabitEthernet2/0/0:
description: "Infra: LAG to xsw0"

View File

@ -84,6 +84,24 @@ def is_bond_member(yaml, ifname):
return True
return False
def unique_lcp(yaml, ifname):
""" Returns true if this interface has a unique LCP name """
if not 'interfaces' in yaml:
return True
iface = get_by_name(yaml, ifname)
lcp = get_lcp(yaml, ifname)
if not lcp:
return True
ncount = 0
for sibling_ifname, sibling_iface in yaml['interfaces'].items():
sibling_lcp = get_lcp(yaml, sibling_ifname)
if sibling_lcp == lcp and sibling_ifname != ifname:
## print("%s overlaps with %s: %s" % (ifname, sibling_ifname, lcp))
ncount = ncount + 1
if ncount == 0:
return True
return False
def has_lcp(yaml, ifname):
""" Returns True if this interface or sub-interface has an LCP"""
@ -263,6 +281,10 @@ def validate_interfaces(args, yaml):
if iface_address and not iface_lcp:
msgs.append("interface %s has adddress(es) but no LCP" % ifname)
result = False
if iface_lcp and not unique_lcp(yaml, ifname):
lcp = get_lcp(yaml, ifname)
msgs.append("interface %s does not have a unique LCP name %s" % (ifname, lcp))
result = False
if has_sub(yaml, ifname):
for sub_id, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items():