forked from EnterpriseDB/postgres-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedb-deployment
More file actions
executable file
·83 lines (67 loc) · 2.3 KB
/
edb-deployment
File metadata and controls
executable file
·83 lines (67 loc) · 2.3 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
import logging
import os
import sys
from edbdeploy import cli
from edbdeploy import command
from edbdeploy.cloud import CloudCliError
from edbdeploy.project import Project, ProjectError
from edbdeploy.terraform import TerraformCliError
from edbdeploy.ansible import AnsibleCliError
from edbdeploy.specifications import SpecValidatorError
def configure_project_logging(project, sub_command):
project.create_log_dir()
logging.basicConfig(
filename=project.log_file,
level=logging.DEBUG,
format='%(asctime)s %(levelname)7s '+sub_command+': %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
def configure_root_logging(cloud, sub_command):
# Configure logging module for the sub-commands that do not take project
# name argument.
Project.create_root_log_dir()
logging.basicConfig(
filename=os.path.join(
Project.projects_root_path, "log", "%s_%s.log" % (cloud, sub_command)
),
level=logging.DEBUG,
format='%(asctime)s %(levelname)7s '+sub_command+': %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
if __name__ == "__main__":
try:
# Parse the commande line
env = cli.parse()
# Create a new Commander in charge of executing the sub-command
commander = command.Commander(env)
# Configure logging
if commander.project:
configure_project_logging(commander.project, env.sub_command)
else:
configure_root_logging(env.cloud, env.sub_command)
logging.debug("env=%s", env)
# Execute the sub-command
commander.execute()
except (
command.CommanderError,
CloudCliError,
ProjectError,
TerraformCliError,
AnsibleCliError,
SpecValidatorError
) as e:
# Update states
if isinstance(e, TerraformCliError):
commander.project.update_state('terraform', 'FAIL')
if isinstance(e, AnsibleCliError):
commander.project.update_state('ansible', 'FAIL')
sys.stderr.write("ERROR: %s\n" % str(e))
sys.exit(2)
except KeyboardInterrupt as e:
sys.exit(1)
except Exception as e:
# Unhandled error
sys.stderr.write("ERROR: %s\n" % str(e))
logging.exception(str(e))
sys.exit(2)