blob: 37f995754238e7962a8f84b0f964c85b21ab3b8a [file] [log] [blame]
Alex Savatieiev5118de02019-02-20 15:50:42 -06001import os
2import sys
Alex3ebc5632019-04-18 16:47:18 -05003from logging import DEBUG, INFO
Alex Savatieiev06ab17d2019-02-26 18:40:48 -06004
Alexbab1efe2019-04-23 18:51:23 -05005from cfg_checker.cli.command import execute_command, helps, parsers
Alex Savatieievc9055712019-03-01 14:43:56 -06006from cfg_checker.common import config, logger, logger_cli
Alex265f45e2019-04-23 18:51:23 -05007from cfg_checker.helpers.args_utils import MyParser
Alex Savatieiev5118de02019-02-20 15:50:42 -06008
9pkg_dir = os.path.dirname(__file__)
10pkg_dir = os.path.normpath(pkg_dir)
11
Alex Savatieiev9c642112019-02-26 13:55:43 -060012
Alex Savatieiev5118de02019-02-20 15:50:42 -060013def config_check_entrypoint():
Alex Savatieiev9c642112019-02-26 13:55:43 -060014 """
Alex3ebc5632019-04-18 16:47:18 -050015 Main entry point. Uses nested parsers structure
Alex Savatieiev9c642112019-02-26 13:55:43 -060016 with a default function to execute the comand
17
18 :return: - no return value
19 """
Alex Savatieiev4c406322019-02-28 17:37:09 -060020 # Main entrypoint
21 parser = MyParser(prog="# Mirantis Cloud configuration checker")
Alex3ebc5632019-04-18 16:47:18 -050022
Alex Savatieiev799bee32019-02-20 17:19:26 -060023 parser.add_argument(
24 "-d",
25 "--debug",
26 action="store_true", default=False,
27 help="Set CLI logging level to DEBUG"
28 )
Alex Savatieiev9c642112019-02-26 13:55:43 -060029 parser.add_argument(
Alex Savatieiev63576832019-02-27 15:46:26 -060030 '-s',
31 '--sudo',
32 action='store_true', default=True,
33 help="Use sudo for getting salt creds"
34 )
Alex Savatieiev5118de02019-02-20 15:50:42 -060035 subparsers = parser.add_subparsers(dest='command')
Alex265f45e2019-04-23 18:51:23 -050036
Alexbab1efe2019-04-23 18:51:23 -050037 # create parsers
38 for _command in helps.keys():
39 _parser = subparsers.add_parser(
40 _command,
41 help=helps[_command]
42 )
43 parsers[_command](_parser)
Alex41485522019-04-12 17:26:18 -050044
Alex3ebc5632019-04-18 16:47:18 -050045 # parse arguments
Alex Savatieiev9c642112019-02-26 13:55:43 -060046 try:
47 args = parser.parse_args()
Alex3ebc5632019-04-18 16:47:18 -050048 except TypeError:
Alex Savatieievc9055712019-03-01 14:43:56 -060049 logger_cli.info("\n# Please, check arguments")
Alex265f45e2019-04-23 18:51:23 -050050 sys.exit(0)
Alex Savatieiev5118de02019-02-20 15:50:42 -060051
Alex Savatieiev63576832019-02-27 15:46:26 -060052 # Pass externally configured values
53 config.ssh_uses_sudo = args.sudo
Alex3ebc5632019-04-18 16:47:18 -050054
Alex Savatieiev799bee32019-02-20 17:19:26 -060055 # Handle options
56 if args.debug:
57 logger_cli.setLevel(DEBUG)
58 else:
59 logger_cli.setLevel(INFO)
60
Alex Savatieiev5118de02019-02-20 15:50:42 -060061 # Execute the command
Alex265f45e2019-04-23 18:51:23 -050062 result = execute_command(args, args.command)
Alex Savatieiev5118de02019-02-20 15:50:42 -060063 logger.debug(result)
Alex265f45e2019-04-23 18:51:23 -050064 sys.exit(result)
Alex Savatieiev4c406322019-02-28 17:37:09 -060065
Alex3ebc5632019-04-18 16:47:18 -050066
Alex Savatieiev4c406322019-02-28 17:37:09 -060067if __name__ == '__main__':
Alex265f45e2019-04-23 18:51:23 -050068 config_check_entrypoint()