Skipping nodes, error handling
diff --git a/cfg_checker/modules/network/checker.py b/cfg_checker/modules/network/checker.py
index 7a654dc..5230039 100644
--- a/cfg_checker/modules/network/checker.py
+++ b/cfg_checker/modules/network/checker.py
@@ -40,6 +40,9 @@
_result = self.execute_script_on_active_nodes("ifs_data.py", args=["json"])
for key in self.nodes.keys():
+ # check if we are to work with this node
+ if not self.is_node_available(key):
+ continue
# due to much data to be passed from salt, it is happening in order
if key in _result:
_text = _result[key]
@@ -59,6 +62,9 @@
# match interfaces by IP subnets
_all_nets = {}
for host, node_data in self.nodes.iteritems():
+ if not self.is_node_available(host):
+ continue
+
for net_name, net_data in node_data['networks'].iteritems():
# get ips and calculate subnets
if net_name in ['lo']:
@@ -89,7 +95,12 @@
# Get required pillars
self.get_specific_pillar_for_nodes("linux:network")
for node in self.nodes.keys():
- _pillar = self.nodes[node]['pillars']['linux']['network']['interface']
+ # check if this node
+ if not self.is_node_available(node):
+ continue
+ # get the reclass value
+ _pillar = self.nodes[node]['pillars']['linux']['network']
+ _pillar = _pillar['interface']
for _if_name, _if_data in _pillar.iteritems():
if 'address' in _if_data:
_if = ipaddress.IPv4Interface(
@@ -116,17 +127,19 @@
"""
_all_nets = self.all_nets.keys()
logger_cli.info("# Reclass networks")
- _text = " {0:17} {1:25}: {2:19} {3:5}{4:10} {5}{6} {7}/{8}/{9}".format(
- "Hostname",
- "IF name",
- "IP",
- "Runtime MTU",
- "Reclass MTU",
- "Runtime State",
- "Reclass State",
- "Runtime gate",
- "Runtime def. gate",
- "Reclass gate"
+ logger_cli.info(
+ " {0:17} {1:25}: {2:19} {3:5}{4:10} {5}{6} {7} / {8} / {9}".format(
+ "Hostname",
+ "IF",
+ "IP",
+ "rtMTU",
+ "rcMTU",
+ "rtState",
+ "rcState",
+ "rtGate",
+ "rtDef.Gate",
+ "rcGate"
+ )
)
_reclass = [n for n in _all_nets if n in self.reclass_nets]
@@ -136,10 +149,21 @@
logger_cli.info("-> {}".format(_net))
names = sorted(self.all_nets[network].keys())
for hostname in names:
+ if not self.is_node_available(hostname, log=False):
+ logger_cli.info(
+ " {0:17} {1}".format(
+ hostname.split('.')[0],
+ "... no data for the node"
+ )
+ )
+
# get the gateway for current net
_routes = self.nodes[hostname]['routes']
_route = _routes[_net] if _net in _routes else None
- _gate = _route['gateway'] if _route['gateway'] else "empty"
+ if not _route:
+ _gate = "no route!"
+ else:
+ _gate = _route['gateway'] if _route['gateway'] else "empty"
# get the default gateway
if 'default' in _routes:
@@ -156,10 +180,16 @@
# Take gateway parameter for this IF
# from corresponding reclass record
_pillar = self.nodes[hostname]['pillars']
- _rd = _pillar['linux']['network']['interface'][_a['name']]
- _r_gate = _rd['gateway'] if 'gateway' in _rd else "empty"
+ _pillar = _pillar['linux']['network']['interface']
+ if not self.is_node_available(hostname):
+ _r_gate = "-"
+ elif _a['name'] not in _pillar:
+ _r_gate = "no IF in reclass!"
+ else:
+ _rd = _pillar[_a['name']]
+ _r_gate = _rd['gateway'] if 'gateway' in _rd else "empty"
- _text = "{0:25}: {1:19} {2:5}{3:10} {4:4}{5:10} {6}/{7}/{8}".format(
+ _text = "{0:25}: {1:19} {2:5}{3:10} {4:4}{5:10} {6} / {7} / {8}".format(
_a['name'],
str(_a['if'].ip),
_a['mtu'],