Add a few additional useful functions
- is_*() returns True if the interface name is of a certain type is_bondethernet() is_loopback() is_bvi() is_bridgedomain() is_vxlan_tunnel() is_phy() - get_phys() by process of elimination, returns all interface names that are supposed to be physical network interfaces. Add unit tests for validator/vxlan_tunnel.py => Notable: while here, fix a bug in get_by_name() Add unit tests for all the is_*() and get_phys() functions.
This commit is contained in:
@ -14,6 +14,8 @@
|
||||
import logging
|
||||
import validator.bondethernet as bondethernet
|
||||
import validator.bridgedomain as bridgedomain
|
||||
import validator.loopback as loopback
|
||||
import validator.vxlan_tunnel as vxlan_tunnel
|
||||
import validator.lcp as lcp
|
||||
import validator.address as address
|
||||
|
||||
@ -237,6 +239,40 @@ def get_encapsulation(yaml, ifname):
|
||||
}
|
||||
|
||||
|
||||
def get_phys(yaml):
|
||||
""" Return a list of all toplevel (ie. non-sub) interfaces which are
|
||||
assumed to be physical network cards, eg TenGigabitEthernet1/0/0. Note
|
||||
that derived/created interfaces such as Tunnels, BondEthernets and
|
||||
Loopbacks/BVIs are not returned """
|
||||
ret = []
|
||||
if not 'interfaces' in yaml:
|
||||
return ret
|
||||
for ifname, iface in yaml['interfaces'].items():
|
||||
if is_phy(yaml, ifname):
|
||||
ret.append(ifname)
|
||||
return ret
|
||||
|
||||
|
||||
def is_phy(yaml, ifname):
|
||||
""" Returns True if the ifname is the name of a physical network interface. """
|
||||
|
||||
ifname, iface = get_by_name(yaml, ifname)
|
||||
if iface == None:
|
||||
return False
|
||||
if is_sub(yaml, ifname):
|
||||
return False
|
||||
|
||||
if bondethernet.is_bondethernet(yaml, ifname):
|
||||
return False
|
||||
if loopback.is_loopback(yaml, ifname):
|
||||
return False
|
||||
if bridgedomain.is_bvi(yaml, ifname):
|
||||
return False
|
||||
if vxlan_tunnel.is_vxlan_tunnel(yaml, ifname):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_interfaces(yaml):
|
||||
""" Return a list of all interface and sub-interface names """
|
||||
ret = []
|
||||
|
Reference in New Issue
Block a user