-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbcd
executable file
·130 lines (115 loc) · 3.62 KB
/
bcd
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
import argparse
import os
import subprocess
import sys
CONTAINERS = (
"database",
"waiverdb",
"greenwave",
"rabbitmq",
"ipsilon",
"bodhi",
)
def ansible(args):
"""Run an ansible playbook command based on the parser name."""
# this is the subcommand that was run - 'run', 'stop' etc.
here = os.path.abspath(os.path.dirname(__file__))
ret = subprocess.run(
(
"ansible-playbook",
f"{here}/devel/ansible-podman/playbook.yml",
f"-e bodhi_dev_{args.subcommand}=true"
)
)
sys.exit(ret.returncode)
def logs(args):
fullc = f"bodhi-dev-{args.container}"
ret = subprocess.run(("podman", "logs", fullc))
sys.exit(ret.returncode)
def shell(args):
fullc = f"bodhi-dev-{args.container}"
ret = subprocess.run(("podman", "exec", "-it", fullc, "/bin/bash"))
sys.exit(ret.returncode)
def parse_args():
"""Parse arguments with argparse."""
parser = argparse.ArgumentParser(
description=(
"Bodhi Container Development environment. Controls a complete Bodhi development "
"environment in Podman containers orchestrated by Ansible."
)
)
subparsers = parser.add_subparsers(dest="subcommand")
subparsers.required = True
parser_run = subparsers.add_parser(
"run",
description="Prepare and run the environment",
aliases=["up"]
)
parser_run.set_defaults(func=ansible)
parser_stop = subparsers.add_parser(
"stop",
description="Stop the environment (does not remove containers)",
aliases=["halt"]
)
parser_stop.set_defaults(func=ansible)
parser_remove = subparsers.add_parser(
"remove",
description="Stop and remove all containers",
aliases=["destroy"]
)
parser_remove.set_defaults(func=ansible)
parser_clean = subparsers.add_parser(
"clean",
description="Stop and remove all containers, remove built images, pull base images",
)
parser_clean.set_defaults(func=ansible)
parser_cis = subparsers.add_parser(
"cis",
description="Clear Ipsilon sessions (to allow you to log in as a different user)"
)
parser_cis.set_defaults(func=ansible)
parser_shell = subparsers.add_parser(
"shell",
description="Open a shell in a container. Container must be running"
)
parser_shell.add_argument(
"container",
help="The container to open a shell in (default: bodhi)",
default="bodhi",
nargs='?',
choices=CONTAINERS
)
parser_shell.set_defaults(func=shell)
parser_logs = subparsers.add_parser(
"logs",
description="Show logs of the specified container (does not work on bodhi, use journalctl)"
)
parser_logs.add_argument(
"container",
help="The container to show logs for",
choices=[cont for cont in CONTAINERS if cont != "bodhi"],
)
parser_logs.set_defaults(func=logs)
parser_prep = subparsers.add_parser(
"prep",
description="Run preparation steps only"
)
parser_prep.set_defaults(func=ansible)
parser_start = subparsers.add_parser(
"start",
description="Start containers only (do not run prep, will fail if prep has not already run)"
)
parser_start.set_defaults(func=ansible)
return parser.parse_args()
def main():
"""Main loop."""
try:
args = parse_args()
args.func(args)
except KeyboardInterrupt:
sys.stderr.write("Interrupted, exiting...\n")
sys.exit(1)
if __name__ == "__main__":
main()
# vim: set textwidth=100 ts=8 et sw=4: