Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 1 | from cfg_checker.common import logger_cli |
Alex | 205546c | 2020-12-30 19:22:30 -0600 | [diff] [blame^] | 2 | from cfg_checker.modules.network.mapper import SaltNetworkMapper, \ |
| 3 | KubeNetworkMapper |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 4 | from cfg_checker.modules.network.network_errors import NetworkErrors |
Alex Savatieiev | f526dc0 | 2019-03-06 10:11:32 -0600 | [diff] [blame] | 5 | from cfg_checker.reports import reporter |
Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 6 | |
| 7 | |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 8 | class NetworkChecker(object): |
Alex | 205546c | 2020-12-30 19:22:30 -0600 | [diff] [blame^] | 9 | def __init__(self): |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 10 | logger_cli.debug("... init error logs folder") |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 11 | self.errors = NetworkErrors() |
| 12 | |
Alex | 836fac8 | 2019-08-22 13:36:16 -0500 | [diff] [blame] | 13 | def check_networks(self, map=True): |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 14 | self.mapper.map_network(self.mapper.RECLASS) |
| 15 | self.mapper.map_network(self.mapper.RUNTIME) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 16 | |
Alex | 836fac8 | 2019-08-22 13:36:16 -0500 | [diff] [blame] | 17 | self.mapper.create_map() |
| 18 | if map: |
| 19 | self.mapper.print_map() |
Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 20 | |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 21 | def print_summary(self): |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 22 | logger_cli.info(self.errors.get_summary(print_zeros=False)) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 23 | |
| 24 | def print_error_details(self): |
| 25 | # Detailed errors |
Alex | b151fbe | 2019-04-22 16:53:30 -0500 | [diff] [blame] | 26 | logger_cli.info( |
| 27 | "\n{}\n".format( |
| 28 | self.errors.get_errors() |
| 29 | ) |
| 30 | ) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 31 | |
Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 32 | def create_html_report(self, filename): |
| 33 | """ |
| 34 | Create static html showing network schema-like report |
| 35 | |
| 36 | :return: none |
| 37 | """ |
| 38 | logger_cli.info("### Generating report to '{}'".format(filename)) |
| 39 | _report = reporter.ReportToFile( |
Alex | 205546c | 2020-12-30 19:22:30 -0600 | [diff] [blame^] | 40 | reporter.HTMLNetworkReport(self.mapper.master), |
Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 41 | filename |
| 42 | ) |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 43 | _report( |
| 44 | { |
| 45 | "domain": self.mapper.domain, |
| 46 | "nodes": self.mapper.nodes, |
| 47 | "map": self.mapper.map, |
| 48 | "mcp_release": self.mapper.cluster['mcp_release'], |
| 49 | "openstack_release": self.mapper.cluster['openstack_release'] |
| 50 | } |
| 51 | ) |
Alex Savatieiev | 9b2f651 | 2019-02-20 18:05:00 -0600 | [diff] [blame] | 52 | logger_cli.info("-> Done") |
Alex | 205546c | 2020-12-30 19:22:30 -0600 | [diff] [blame^] | 53 | |
| 54 | |
| 55 | class SaltNetworkChecker(NetworkChecker): |
| 56 | def __init__( |
| 57 | self, |
| 58 | config, |
| 59 | skip_list=None, |
| 60 | skip_list_file=None |
| 61 | ): |
| 62 | super(SaltNetworkChecker, self).__init__() |
| 63 | self.mapper = SaltNetworkMapper( |
| 64 | config, |
| 65 | errors_class=self.errors, |
| 66 | skip_list=skip_list, |
| 67 | skip_list_file=skip_list_file |
| 68 | ) |
| 69 | |
| 70 | class KubeNetworkChecker(NetworkChecker): |
| 71 | def __init__( |
| 72 | self, |
| 73 | config, |
| 74 | skip_list=None, |
| 75 | skip_list_file=None |
| 76 | ): |
| 77 | super(SaltNetworkChecker, self).__init__() |
| 78 | self.mapper = KubeNetworkMapper( |
| 79 | config, |
| 80 | errors_class=self.errors, |
| 81 | skip_list=skip_list, |
| 82 | skip_list_file=skip_list_file |
| 83 | ) |