Add get_lcps() to enumerate all LCP names in the system
This commit is contained in:
@ -13,23 +13,32 @@
|
||||
#
|
||||
import logging
|
||||
|
||||
def is_unique(yaml, lcpname):
|
||||
""" Returns True if there is at most one occurence of the LCP name in the entire config."""
|
||||
ncount=0
|
||||
def get_lcps(yaml):
|
||||
""" Returns a list of all LCPs configured in the system, or an empty list if there are none. """
|
||||
|
||||
ret = []
|
||||
if 'interfaces' in yaml:
|
||||
for ifname, iface in yaml['interfaces'].items():
|
||||
if 'lcp' in iface and iface['lcp'] == lcpname:
|
||||
ncount = ncount + 1
|
||||
if 'lcp' in iface:
|
||||
ret.append(iface['lcp'])
|
||||
if 'sub-interfaces' in iface:
|
||||
for sub_ifname, sub_iface in iface['sub-interfaces'].items():
|
||||
if 'lcp' in sub_iface and sub_iface['lcp'] == lcpname:
|
||||
ncount = ncount + 1
|
||||
if 'lcp' in sub_iface:
|
||||
ret.append(sub_iface['lcp'])
|
||||
|
||||
if 'loopbacks' in yaml:
|
||||
for ifname, iface in yaml['loopbacks'].items():
|
||||
if 'lcp' in iface and iface['lcp'] == lcpname:
|
||||
ncount = ncount + 1
|
||||
if 'lcp' in iface:
|
||||
ret.append(iface['lcp'])
|
||||
if 'bridgedomains' in yaml:
|
||||
for ifname, iface in yaml['bridgedomains'].items():
|
||||
if 'lcp' in iface and iface['lcp'] == lcpname:
|
||||
ncount = ncount + 1
|
||||
return ncount < 2
|
||||
if 'lcp' in iface:
|
||||
ret.append(iface['lcp'])
|
||||
|
||||
return ret
|
||||
|
||||
def is_unique(yaml, lcpname):
|
||||
""" Returns True if there is at most one occurence of the LCP name in the entire config."""
|
||||
|
||||
lcps = get_lcps(yaml)
|
||||
return lcps.count(lcpname) < 2
|
||||
|
Reference in New Issue
Block a user