blob: 78436d69ac712c06abfbefada5fb5906cbc1e933 [file] [log] [blame]
Alex Savatieiev5118de02019-02-20 15:50:42 -06001import argparse
2import os
3import sys
4
5import reporter
6from cfg_checker.common import utils, const
7from cfg_checker.common import config, logger, logger_cli, pkg_dir
8from cfg_checker.clients import salt
9
10from cfg_checker.pkg_check import CloudPackageChecker
11
12pkg_dir = os.path.dirname(__file__)
13pkg_dir = os.path.normpath(pkg_dir)
14
15
16class MyParser(argparse.ArgumentParser):
17 def error(self, message):
18 sys.stderr.write('Error: {0}\n\n'.format(message))
19 self.print_help()
20
21
22
23def help_message():
24 print"""
25 Please, use following examples to generate info reports:\n
26 cfg_checker packages report\n
27 cfg_checker network check\n
28 cfg_checker network report\n
29 """
30 return
31
32def pkg_check(args):
33 # create package versions report
Alex Savatieieve47f7f42019-02-20 16:41:23 -060034 if args.file:
35 _filename = args.file
36 else:
37 logger_cli.error("ERROR: no report filename supplied")
38 return
Alex Savatieiev5118de02019-02-20 15:50:42 -060039 # init connection to salt and collect minion data
40 pChecker = CloudPackageChecker()
41 # collect data on installed packages
42 pChecker.collect_installed_packages()
43 # diff installed and candidates
44 # pChecker.collect_packages()
45 # report it
46 pChecker.create_html_report(_filename)
47
48
49def net_check(args):
50 print("This is net check routine")
51
52 return
53
54
55def net_report(args):
56 print("This is net check routine")
57
58 return
59
60
61def config_check_entrypoint():
62 # Main entrypointр
63 parser = MyParser(prog="Cloud configuration checker")
64 subparsers = parser.add_subparsers(dest='command')
65 # packages
66 pkg_parser = subparsers.add_parser(
67 'packages',
68 help="Package versions check (Candidate vs Installed)"
69 )
70 pkg_subparsers = pkg_parser.add_subparsers(dest='type')
71
72 pkg_report_parser = pkg_subparsers.add_parser(
73 'report',
74 help="Report package versions to HTML file"
75 )
76 pkg_report_parser.add_argument(
77 '-f',
78 '--file',
79 help="HTML filename to save report"
80 )
Alex Savatieieve47f7f42019-02-20 16:41:23 -060081 pkg_report_parser.set_defaults(func=pkg_check)
Alex Savatieiev5118de02019-02-20 15:50:42 -060082
83 # networking
84 net_parser = subparsers.add_parser(
85 'network',
86 help="Network infrastructure checks"
87 )
88 net_subparsers = net_parser.add_subparsers(dest='type')
89
90 net_check_parser = net_subparsers.add_parser(
91 'check',
92 help="Do network check and print the result"
93 )
94 net_check_parser.set_defaults(func=net_check)
95
96 net_report_parser = net_subparsers.add_parser(
97 'report',
98 help="Generate network check report"
99 )
100 net_report_parser.add_argument(
101 '-f',
102 '--file',
103 help="HTML filename to save report"
104 )
105 net_report_parser.set_defaults(func=net_report)
106
107 #parse arguments
108 args = parser.parse_args()
109
110 # Execute the command
111 result = args.func(args)
112
113 logger.debug(result)
114 return
115
116if __name__ == '__main__':
Alex Savatieieve47f7f42019-02-20 16:41:23 -0600117 try:
118 config_check_entrypoint()
119 except Exception as e:
120 logger_cli.error("ERROR: {}".format(e.message))