-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·58 lines (44 loc) · 2.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
import argparse
import logging
import clilib.utils as utils
from clilib.cloud_cli import CloudCLI
if __name__ == "__main__":
allowed_actions = ["create", "cleanup", "prepare_ansible", "run_ansible"]
# setup command line arguments
parser = argparse.ArgumentParser(description="CPSWTNG Cloud CLI tool")
parser.add_argument("-a", "--action", choices=allowed_actions,
required=True, help="the action to do")
parser.add_argument("-c", "--config", type=argparse.FileType('r'),
help="path to the configuration file")
parser.add_argument("-v", "--verbose",
help="set verbosity mode", action="count")
parser.add_argument("project", nargs=1, help="the name of the project")
# parse command line args
args = parser.parse_args()
action = args.action
config_file = "config/default.yml"
if args.config:
config_file = args.config
cli_config = utils.load_yaml_config(config_file)
verbose_level = args.verbose
project_name_in = args.project[0].lower()
project_name = ''.join(c for c in project_name_in if c.isalnum())
# setup logger
logging.basicConfig(level=utils.get_log_level(verbose_level))
logging.getLogger().addHandler(logging.FileHandler("cloud_cli.log"))
logger = logging.getLogger(__name__)
# overwrite config.project with the passed value (may be different)
cli_config['project'] = project_name
logger.info("Starting Lusheeta CLI...")
if project_name_in != project_name:
logger.info("Passed project name was cleaned (%s -> %s)",
project_name_in, project_name)
logger.debug("Allowed actions for the CLI: %s", allowed_actions)
logger.debug("Passed args:\t"
"action = '%s'\t"
"config_file = '%s'\t"
"verbose_level = '%s'\t"
"project_name = '%s'", action, config_file, verbose_level, project_name)
cli = CloudCLI(action=action, config=cli_config, project_name=project_name)
cli.run()