| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 1 | import ipaddress | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 2 | import json | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 3 |  | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 4 |  | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 5 | from cfg_checker.common import logger_cli | 
|  | 6 | from cfg_checker.modules.network.network_errors import NetworkErrors | 
|  | 7 | from cfg_checker.nodes import SaltNodes | 
| Alex Savatieiev | f526dc0 | 2019-03-06 10:11:32 -0600 | [diff] [blame] | 8 | from cfg_checker.reports import reporter | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 9 |  | 
|  | 10 |  | 
|  | 11 | class NetworkChecker(SaltNodes): | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 12 | def __init__(self): | 
|  | 13 | super(NetworkChecker, self).__init__() | 
|  | 14 | self.errors = NetworkErrors() | 
|  | 15 |  | 
|  | 16 | # adding net data to tree | 
|  | 17 | def _add_data(self, _list, _n, _h, _d): | 
|  | 18 | if _n not in _list: | 
|  | 19 | _list[_n] = {} | 
|  | 20 | _list[_n][_h] = [_d] | 
|  | 21 | elif _h not in _list[_n]: | 
|  | 22 | # there is no such host, just create it | 
|  | 23 | _list[_n][_h] = [_d] | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 24 | else: | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 25 | # there is such host... this is an error | 
|  | 26 | self.errors.add_error( | 
|  | 27 | self.errors.NET_DUPLICATE_IF, | 
|  | 28 | host=_h, | 
|  | 29 | dup_if=_d['name'] | 
|  | 30 | ) | 
|  | 31 | _list[_n][_h].append(_d) | 
|  | 32 |  | 
|  | 33 | # TODO: refactor map creation. Build one map instead of two separate | 
|  | 34 | def _map_network_for_host(self, host, if_class, net_list, data): | 
|  | 35 | # filter networks for this IF IP | 
|  | 36 | _nets = [n for n in net_list.keys() if if_class.ip in n] | 
|  | 37 | _masks = [n.netmask for n in _nets] | 
|  | 38 | if len(_nets) > 1: | 
|  | 39 | # There a multiple network found for this IP, Error | 
|  | 40 | self.errors.add_error( | 
|  | 41 | self.errors.NET_SUBNET_INTERSECT, | 
|  | 42 | host=host, | 
|  | 43 | networks="; ".join(_nets) | 
|  | 44 | ) | 
|  | 45 | # check mask match | 
|  | 46 | if len(_nets) > 0 and if_class.netmask not in _masks: | 
|  | 47 | self.errors.add_error( | 
|  | 48 | self.errors.NET_MASK_MISMATCH, | 
|  | 49 | host=host, | 
|  | 50 | if_name=data['name'], | 
|  | 51 | if_cidr=if_class.exploded, | 
|  | 52 | if_mapped_networks=", ".join([str(_n) for _n in _nets]) | 
|  | 53 | ) | 
|  | 54 |  | 
|  | 55 | if len(_nets) < 1: | 
|  | 56 | self._add_data(net_list, if_class.network, host, data) | 
|  | 57 | else: | 
|  | 58 | # add all data | 
|  | 59 | for net in _nets: | 
|  | 60 | self._add_data(net_list, net, host, data) | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 61 |  | 
|  | 62 | return net_list | 
|  | 63 |  | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 64 | def collect_network_info(self): | 
|  | 65 | """ | 
|  | 66 | Collects info on the network using ifs_data.py script | 
|  | 67 |  | 
|  | 68 | :return: none | 
|  | 69 | """ | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 70 | logger_cli.info("# Mapping node runtime network data") | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 71 | _result = self.execute_script_on_active_nodes( | 
|  | 72 | "ifs_data.py", | 
|  | 73 | args=["json"] | 
|  | 74 | ) | 
|  | 75 | self.stage = "Runtime" | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 76 | for key in self.nodes.keys(): | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 77 | # check if we are to work with this node | 
|  | 78 | if not self.is_node_available(key): | 
|  | 79 | continue | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 80 | # due to much data to be passed from salt, it is happening in order | 
|  | 81 | if key in _result: | 
|  | 82 | _text = _result[key] | 
|  | 83 | _dict = json.loads(_text[_text.find('{'):]) | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 84 | self.nodes[key]['routes'] = _dict.pop("routes") | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 85 | self.nodes[key]['networks'] = _dict | 
|  | 86 | else: | 
|  | 87 | self.nodes[key]['networks'] = {} | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 88 | self.nodes[key]['routes'] = {} | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 89 | logger_cli.debug("... {} has {} networks".format( | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 90 | key, | 
|  | 91 | len(self.nodes[key]['networks'].keys()) | 
|  | 92 | )) | 
| Alex Savatieiev | f808cd2 | 2019-03-01 13:17:59 -0600 | [diff] [blame] | 93 | logger_cli.info("-> done collecting networks data") | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 94 |  | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 95 | # TODO: Mimic reclass structure for easy compare | 
| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 96 | logger_cli.info("### Building network tree") | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 97 | # match interfaces by IP subnets | 
| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 98 | _all_nets = {} | 
| Alex Savatieiev | a05921f | 2019-02-21 18:21:39 -0600 | [diff] [blame] | 99 | for host, node_data in self.nodes.iteritems(): | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 100 | if not self.is_node_available(host): | 
|  | 101 | continue | 
|  | 102 |  | 
| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 103 | for net_name, net_data in node_data['networks'].iteritems(): | 
|  | 104 | # get ips and calculate subnets | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 105 | if net_name in ['lo']: | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 106 | # skip the localhost | 
| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 107 | continue | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 108 | #  get data and make sure that wide mask goes first | 
|  | 109 | _ip4s = sorted( | 
|  | 110 | net_data['ipv4'], | 
|  | 111 | key=lambda s: s[s.index('/'):] | 
|  | 112 | ) | 
|  | 113 | for _ip_str in _ip4s: | 
|  | 114 | # create interface class | 
| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 115 | _if = ipaddress.IPv4Interface(_ip_str) | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 116 | if 'name' not in net_data: | 
|  | 117 | net_data['name'] = net_name | 
|  | 118 | if 'ifs' not in net_data: | 
|  | 119 | net_data['ifs'] = [_if] | 
|  | 120 | # map it | 
|  | 121 | _all_nets = self._map_network_for_host( | 
|  | 122 | host, | 
|  | 123 | _if, | 
|  | 124 | _all_nets, | 
|  | 125 | net_data | 
|  | 126 | ) | 
|  | 127 | else: | 
|  | 128 | # data is already there, just add VIP | 
|  | 129 | net_data['ifs'].append(_if) | 
| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 130 |  | 
|  | 131 | # save collected info | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 132 | self.all_nets = _all_nets | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 133 |  | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 134 | def collect_reclass_networks(self): | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 135 | logger_cli.info("# Mapping reclass networks") | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 136 | self.stage = "Reclass" | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 137 | # Get networks from reclass and mark them | 
|  | 138 | _reclass_nets = {} | 
|  | 139 | # Get required pillars | 
|  | 140 | self.get_specific_pillar_for_nodes("linux:network") | 
|  | 141 | for node in self.nodes.keys(): | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 142 | # check if this node | 
|  | 143 | if not self.is_node_available(node): | 
|  | 144 | continue | 
|  | 145 | # get the reclass value | 
|  | 146 | _pillar = self.nodes[node]['pillars']['linux']['network'] | 
| Alex Savatieiev | a1f6f8c | 2019-03-18 17:13:55 -0500 | [diff] [blame] | 147 | # we should be ready if there is no interface in reclass for a node | 
|  | 148 | # for example on APT node | 
|  | 149 | if 'interface' in _pillar: | 
|  | 150 | _pillar = _pillar['interface'] | 
|  | 151 | else: | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 152 | logger_cli.info( | 
|  | 153 | "... node '{}' skipped, no IF section in reclass".format( | 
|  | 154 | node | 
|  | 155 | ) | 
|  | 156 | ) | 
| Alex Savatieiev | a1f6f8c | 2019-03-18 17:13:55 -0500 | [diff] [blame] | 157 | continue | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 158 | for _if_name, _if_data in _pillar.iteritems(): | 
|  | 159 | if 'address' in _if_data: | 
|  | 160 | _if = ipaddress.IPv4Interface( | 
|  | 161 | _if_data['address'] + '/' + _if_data['netmask'] | 
|  | 162 | ) | 
|  | 163 | _if_data['name'] = _if_name | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 164 | _if_data['ifs'] = [_if] | 
| Alex Savatieiev | 01f0d7f | 2019-03-07 17:53:29 -0600 | [diff] [blame] | 165 |  | 
|  | 166 | _reclass_nets = self._map_network_for_host( | 
|  | 167 | node, | 
|  | 168 | _if, | 
|  | 169 | _reclass_nets, | 
|  | 170 | _if_data | 
|  | 171 | ) | 
|  | 172 |  | 
|  | 173 | self.reclass_nets = _reclass_nets | 
|  | 174 |  | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 175 | def print_network_report(self): | 
|  | 176 | """ | 
|  | 177 | Create text report for CLI | 
|  | 178 |  | 
|  | 179 | :return: none | 
|  | 180 | """ | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 181 | _all_nets = self.all_nets.keys() | 
|  | 182 | logger_cli.info("# Reclass networks") | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 183 | logger_cli.info( | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 184 | "    {0:17} {1:25}: " | 
|  | 185 | "{2:19} {3:5}{4:10} {5}{6} {7} / {8} / {9}".format( | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 186 | "Hostname", | 
|  | 187 | "IF", | 
|  | 188 | "IP", | 
|  | 189 | "rtMTU", | 
|  | 190 | "rcMTU", | 
|  | 191 | "rtState", | 
|  | 192 | "rcState", | 
|  | 193 | "rtGate", | 
|  | 194 | "rtDef.Gate", | 
|  | 195 | "rcGate" | 
|  | 196 | ) | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 197 | ) | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 198 | # TODO: Move matching to separate function | 
|  | 199 | self.stage = "Matching" | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 200 | _reclass = [n for n in _all_nets if n in self.reclass_nets] | 
|  | 201 | for network in _reclass: | 
|  | 202 | # shortcuts | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 203 | _net = str(network) | 
|  | 204 | logger_cli.info("-> {}".format(_net)) | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 205 | names = sorted(self.all_nets[network].keys()) | 
| Alex Savatieiev | e961399 | 2019-02-21 18:20:35 -0600 | [diff] [blame] | 206 | for hostname in names: | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 207 | if not self.is_node_available(hostname, log=False): | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 208 | logger_cli.info( | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 209 | "    {0:17} {1}".format( | 
|  | 210 | hostname.split('.')[0], | 
|  | 211 | "... no data for the node" | 
|  | 212 | ) | 
|  | 213 | ) | 
| Alex | ec688e0 | 2019-04-22 12:05:06 -0500 | [diff] [blame^] | 214 | # add non-responsive node erorr | 
|  | 215 | self.errors.add_error( | 
|  | 216 | self.errors.NET_NODE_NON_RESPONSIVE, | 
|  | 217 | host=hostname | 
|  | 218 | ) | 
|  | 219 |  | 
|  | 220 | # print empty row | 
|  | 221 | _text = " # node non-responsive" | 
|  | 222 | logger_cli.info( | 
|  | 223 | "    {0:17} {1}".format( | 
|  | 224 | hostname.split('.')[0], | 
|  | 225 | _text | 
|  | 226 | ) | 
|  | 227 | ) | 
|  | 228 | continue | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 229 |  | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 230 | # get the gateway for current net | 
|  | 231 | _routes = self.nodes[hostname]['routes'] | 
|  | 232 | _route = _routes[_net] if _net in _routes else None | 
| Alex Savatieiev | efa79c4 | 2019-03-14 19:14:04 -0500 | [diff] [blame] | 233 | if not _route: | 
|  | 234 | _gate = "no route!" | 
|  | 235 | else: | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 236 | _gate = _route['gateway'] if _route['gateway'] else "-" | 
|  | 237 |  | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 238 | # get the default gateway | 
|  | 239 | if 'default' in _routes: | 
|  | 240 | _d_gate = ipaddress.IPv4Address( | 
|  | 241 | _routes['default']['gateway'] | 
|  | 242 | ) | 
|  | 243 | else: | 
|  | 244 | _d_gate = None | 
|  | 245 | _d_gate_str = _d_gate if _d_gate else "No default gateway!" | 
|  | 246 |  | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 247 | _a = self.all_nets[network][hostname] | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 248 | for _host in _a: | 
|  | 249 | for _if in _host['ifs']: | 
|  | 250 | # get proper reclass | 
|  | 251 | _ip_str = str(_if.exploded) | 
|  | 252 | _r = {} | 
| Alex | ec688e0 | 2019-04-22 12:05:06 -0500 | [diff] [blame^] | 253 | if hostname in self.reclass_nets[network]: | 
|  | 254 | for _item in self.reclass_nets[network][hostname]: | 
|  | 255 | for _item_ifs in _item['ifs']: | 
|  | 256 | if _ip_str == str(_item_ifs.exploded): | 
|  | 257 | _r = _item | 
|  | 258 | else: | 
|  | 259 | self.errors.add_error( | 
|  | 260 | self.errors.NET_NODE_UNEXPECTED_IF, | 
|  | 261 | host=hostname, | 
|  | 262 | if_name=_host['name'], | 
|  | 263 | if_ip=_ip_str | 
|  | 264 | ) | 
| Alex Savatieiev | d79dde1 | 2019-03-13 19:07:46 -0500 | [diff] [blame] | 265 |  | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 266 | # check if node is UP | 
|  | 267 | if not self.is_node_available(hostname): | 
|  | 268 | _r_gate = "-" | 
|  | 269 | # get proper network from reclass | 
|  | 270 | else: | 
|  | 271 | # Lookup match for the ip | 
|  | 272 | _r_gate = "no IF in reclass!" | 
|  | 273 | # get all networks with this hostname | 
|  | 274 | _rn = self.reclass_nets | 
|  | 275 | _nets = filter( | 
|  | 276 | lambda n: hostname in _rn[n].keys(), | 
|  | 277 | self.reclass_nets | 
|  | 278 | ) | 
|  | 279 | _rd = None | 
|  | 280 | for _item in _nets: | 
|  | 281 | # match ip | 
|  | 282 | _r_dat = self.reclass_nets[_item][hostname] | 
|  | 283 | for _r_ifs in _r_dat: | 
|  | 284 | for _r_if in _r_ifs['ifs']: | 
|  | 285 | if _if.ip == _r_if.ip: | 
|  | 286 | _rd = _r_ifs | 
|  | 287 | break | 
|  | 288 | if _rd: | 
|  | 289 | _gs = 'gateway' | 
|  | 290 | _e = "empty" | 
|  | 291 | _r_gate = _rd[_gs] if _gs in _rd else _e | 
|  | 292 | break | 
|  | 293 |  | 
|  | 294 | # IF status in reclass | 
|  | 295 | if 'enabled' not in _r: | 
| Alex | ec688e0 | 2019-04-22 12:05:06 -0500 | [diff] [blame^] | 296 | _enabled = "(no record!)" | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 297 | else: | 
|  | 298 | _e = "enabled" | 
|  | 299 | _d = "disabled" | 
|  | 300 | _enabled = "("+_e+")" if _r[_e] else "("+_d+")" | 
|  | 301 |  | 
|  | 302 | _name = _host['name'] | 
|  | 303 | _rc_mtu = _r['mtu'] if 'mtu' in _r else None | 
|  | 304 |  | 
|  | 305 | # Check if this is a VIP | 
|  | 306 | if _if.network.prefixlen == 32: | 
|  | 307 | _name = " "*20 | 
|  | 308 | _ip_str += " VIP" | 
|  | 309 | _rc_mtu = "(-)" | 
|  | 310 | _enabled = "(-)" | 
|  | 311 | _r_gate = "-" | 
|  | 312 |  | 
|  | 313 | # Check if this is a default MTU | 
|  | 314 | elif _host['mtu'] == '1500': | 
|  | 315 | # reclass is empty if MTU is untended to be 1500 | 
|  | 316 | _rc_mtu = "(-)" | 
|  | 317 | elif _rc_mtu: | 
| Alex | ec688e0 | 2019-04-22 12:05:06 -0500 | [diff] [blame^] | 318 | _rc_mtu_s = str(_rc_mtu) | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 319 | # if there is an MTU value, match it | 
| Alex | ec688e0 | 2019-04-22 12:05:06 -0500 | [diff] [blame^] | 320 | if _host['mtu'] != _rc_mtu_s: | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 321 | self.errors.add_error( | 
|  | 322 | self.errors.NET_MTU_MISMATCH, | 
|  | 323 | host=hostname, | 
|  | 324 | if_name=_name, | 
|  | 325 | if_cidr=_ip_str, | 
|  | 326 | reclass_mtu=_rc_mtu, | 
|  | 327 | runtime_mtu=_host['mtu'] | 
|  | 328 | ) | 
|  | 329 | else: | 
|  | 330 | # there is no MTU value in reclass | 
|  | 331 | self.errors.add_error( | 
|  | 332 | self.errors.NET_MTU_EMPTY, | 
|  | 333 | host=hostname, | 
|  | 334 | if_name=_name, | 
|  | 335 | if_cidr=_ip_str, | 
|  | 336 | if_mtu=_host['mtu'] | 
|  | 337 | ) | 
|  | 338 |  | 
| Alex | a05f74e | 2019-04-22 10:57:25 -0500 | [diff] [blame] | 339 | _text = "{0:25} {1:19} {2:5}{3:10} {4:4}{5:10} " \ | 
|  | 340 | "{6} / {7} / {8}".format( | 
|  | 341 | _name, | 
|  | 342 | _ip_str, | 
|  | 343 | _host['mtu'], | 
| Alex | ec688e0 | 2019-04-22 12:05:06 -0500 | [diff] [blame^] | 344 | "("+_rc_mtu_s+")" if _rc_mtu else "(No!)", | 
| Alex | a05f74e | 2019-04-22 10:57:25 -0500 | [diff] [blame] | 345 | _host['state'], | 
|  | 346 | _enabled, | 
|  | 347 | _gate, | 
|  | 348 | _d_gate_str, | 
|  | 349 | _r_gate | 
|  | 350 | ) | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 351 | logger_cli.info( | 
|  | 352 | "    {0:17} {1}".format( | 
|  | 353 | hostname.split('.')[0], | 
|  | 354 | _text | 
|  | 355 | ) | 
|  | 356 | ) | 
|  | 357 |  | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 358 | logger_cli.info("\n# Other networks") | 
|  | 359 | _other = [n for n in _all_nets if n not in self.reclass_nets] | 
|  | 360 | for network in _other: | 
|  | 361 | logger_cli.info("-> {}".format(str(network))) | 
|  | 362 | names = sorted(self.all_nets[network].keys()) | 
|  | 363 |  | 
|  | 364 | for hostname in names: | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 365 | for _n in self.all_nets[network][hostname]: | 
|  | 366 | _ifs = [str(ifs.ip) for ifs in _n['ifs']] | 
|  | 367 | _text = "{0:25}: {1:19} {2:5} {3:4}".format( | 
|  | 368 | _n['name'], | 
|  | 369 | ", ".join(_ifs), | 
|  | 370 | _n['mtu'], | 
|  | 371 | _n['state'] | 
|  | 372 | ) | 
|  | 373 | logger_cli.info( | 
|  | 374 | "    {0:17} {1}".format(hostname.split('.')[0], _text) | 
|  | 375 | ) | 
| Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 376 |  | 
| Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 377 | def print_summary(self): | 
|  | 378 | _total_errors = self.errors.get_errors_total() | 
|  | 379 | # Summary | 
|  | 380 | logger_cli.info( | 
|  | 381 | "\n{:=^8s}\n{:^8s}\n{:=^8s}".format( | 
|  | 382 | "=", | 
|  | 383 | "Totals", | 
|  | 384 | "=" | 
|  | 385 | ) | 
|  | 386 | ) | 
|  | 387 | logger_cli.info(self.errors.get_summary(print_zeros=False)) | 
|  | 388 | logger_cli.info('-'*20) | 
|  | 389 | logger_cli.info("{:5d} total errors found\n".format(_total_errors)) | 
|  | 390 |  | 
|  | 391 | def print_error_details(self): | 
|  | 392 | # Detailed errors | 
|  | 393 | if self.errors.get_errors_total() > 0: | 
|  | 394 | logger_cli.info("\n# Errors") | 
|  | 395 | for _msg in self.errors.get_errors_as_list(): | 
|  | 396 | logger_cli.info("{}\n".format(_msg)) | 
|  | 397 | else: | 
|  | 398 | logger_cli.info("-> No errors\n") | 
|  | 399 |  | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 400 | def create_html_report(self, filename): | 
|  | 401 | """ | 
|  | 402 | Create static html showing network schema-like report | 
|  | 403 |  | 
|  | 404 | :return: none | 
|  | 405 | """ | 
|  | 406 | logger_cli.info("### Generating report to '{}'".format(filename)) | 
|  | 407 | _report = reporter.ReportToFile( | 
|  | 408 | reporter.HTMLNetworkReport(), | 
|  | 409 | filename | 
|  | 410 | ) | 
|  | 411 | _report({ | 
|  | 412 | "nodes": self.nodes, | 
| Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 413 | "network": {}, | 
|  | 414 | "mcp_release": self.mcp_release, | 
|  | 415 | "openstack_release": self.openstack_release | 
|  | 416 |  | 
| Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 417 | }) | 
|  | 418 | logger_cli.info("-> Done") |