Rewrite 'exists' to 'get_by_name'
This commit is contained in:
@ -6,14 +6,15 @@ class NullHandler(logging.Handler):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def exists(yaml, ifname):
|
def get_by_name(yaml, ifname):
|
||||||
""" Return True if the BondEthernet exists """
|
""" Return the BondEthernet by name, if it exists. Return None otherwise. """
|
||||||
try:
|
try:
|
||||||
if ifname in yaml['bondethernets']:
|
if ifname in yaml['bondethernets']:
|
||||||
return True
|
return yaml['bondethernets'][ifname]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return False
|
return None
|
||||||
|
|
||||||
|
|
||||||
def bondethernet(args, yaml):
|
def bondethernet(args, yaml):
|
||||||
result = True
|
result = True
|
||||||
@ -27,7 +28,7 @@ def bondethernet(args, yaml):
|
|||||||
for ifname, iface in yaml['bondethernets'].items():
|
for ifname, iface in yaml['bondethernets'].items():
|
||||||
logger.debug("bondethernet %s: %s" % (ifname, iface))
|
logger.debug("bondethernet %s: %s" % (ifname, iface))
|
||||||
for member in iface['interfaces']:
|
for member in iface['interfaces']:
|
||||||
if not interface.exists(yaml, member):
|
if not interface.get_by_name(yaml, member):
|
||||||
msgs.append("bondethernet %s member %s doesn't exist" % (ifname, member))
|
msgs.append("bondethernet %s member %s doesn't exist" % (ifname, member))
|
||||||
result = False
|
result = False
|
||||||
|
|
||||||
|
@ -5,6 +5,25 @@ class NullHandler(logging.Handler):
|
|||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_by_name(yaml, ifname):
|
||||||
|
""" Returns the interface or sub-interface by a given name, or None if it does not exist """
|
||||||
|
if '.' in ifname:
|
||||||
|
ifname, subid = ifname.split('.')
|
||||||
|
subid = int(subid)
|
||||||
|
try:
|
||||||
|
iface = yaml['interfaces'][ifname]['sub-interfaces'][subid]
|
||||||
|
return iface
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
iface = yaml['interfaces'][ifname]
|
||||||
|
return iface
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def has_sub(yaml, ifname):
|
def has_sub(yaml, ifname):
|
||||||
""" Returns True if this interface has sub-interfaces """
|
""" Returns True if this interface has sub-interfaces """
|
||||||
if not 'interfaces' in yaml:
|
if not 'interfaces' in yaml:
|
||||||
@ -16,6 +35,7 @@ def has_sub(yaml, ifname):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def has_address(yaml, ifname):
|
def has_address(yaml, ifname):
|
||||||
""" Returns True if this interface or sub-interface has one or more addresses"""
|
""" Returns True if this interface or sub-interface has one or more addresses"""
|
||||||
if not 'interfaces' in yaml:
|
if not 'interfaces' in yaml:
|
||||||
@ -38,6 +58,7 @@ def has_address(yaml, ifname):
|
|||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_bond_member(yaml, ifname):
|
def is_bond_member(yaml, ifname):
|
||||||
""" Returns True if this interface is a member of a BondEthernet """
|
""" Returns True if this interface is a member of a BondEthernet """
|
||||||
if not 'bondethernets' in yaml:
|
if not 'bondethernets' in yaml:
|
||||||
@ -50,6 +71,7 @@ def is_bond_member(yaml, ifname):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def has_lcp(yaml, ifname):
|
def has_lcp(yaml, ifname):
|
||||||
""" Returns True if this interface or sub-interface has an LCP"""
|
""" Returns True if this interface or sub-interface has an LCP"""
|
||||||
if not 'interfaces' in yaml:
|
if not 'interfaces' in yaml:
|
||||||
@ -72,19 +94,6 @@ def has_lcp(yaml, ifname):
|
|||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def exists(yaml, ifname):
|
|
||||||
""" Returns true if ifname exists as a phy or sub-int """
|
|
||||||
try:
|
|
||||||
if ifname in yaml['interfaces']:
|
|
||||||
return True
|
|
||||||
if '.' in ifname:
|
|
||||||
ifname, subid = ifname.split('.')
|
|
||||||
subid = int(subid)
|
|
||||||
if subid in yaml['interfaces'][ifname]['sub-interfaces']:
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return False
|
|
||||||
|
|
||||||
def valid_encapsulation(yaml, sub_ifname):
|
def valid_encapsulation(yaml, sub_ifname):
|
||||||
try:
|
try:
|
||||||
@ -117,7 +126,7 @@ def interface(args, yaml):
|
|||||||
|
|
||||||
for ifname, iface in yaml['interfaces'].items():
|
for ifname, iface in yaml['interfaces'].items():
|
||||||
logger.debug("interface %s" % iface)
|
logger.debug("interface %s" % iface)
|
||||||
if ifname.startswith("BondEthernet") and not bondethernet.exists(yaml, ifname):
|
if ifname.startswith("BondEthernet") and not bondethernet.get_by_name(yaml, ifname):
|
||||||
msgs.append("interface %s does not exist in bondethernets" % ifname)
|
msgs.append("interface %s does not exist in bondethernets" % ifname)
|
||||||
result = False
|
result = False
|
||||||
|
|
||||||
|
@ -4,14 +4,14 @@ class NullHandler(logging.Handler):
|
|||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def exists(yaml, ifname):
|
def get_by_name(yaml, ifname):
|
||||||
""" Returns true if ifname exists as a loopback """
|
""" Return the loopback by name, if it exists. Return None otherwise. """
|
||||||
try:
|
try:
|
||||||
if ifname in yaml['loopbacks']:
|
if ifname in yaml['loopbacks']:
|
||||||
return True
|
return yaml['loopbacks'][ifname]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return False
|
return None
|
||||||
|
|
||||||
|
|
||||||
def loopback(args, yaml):
|
def loopback(args, yaml):
|
||||||
|
Reference in New Issue
Block a user