-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.py
executable file
·183 lines (166 loc) · 5.1 KB
/
run.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python3
import argparse
import subprocess
import os
class DriverOpenStack:
@staticmethod
def cleanup(args):
subprocess.check_call(
[
"ansible-playbook",
"openstack/playbooks/clean.yaml",
"-e",
"prefix=%s" % args.prefix,
]
)
@staticmethod
def purge(args):
subprocess.check_call(
[
"ansible-playbook",
"openstack/playbooks/purge.yaml",
"-e",
"prefix=%s" % args.prefix,
]
)
@staticmethod
def deploy(args):
subprocess.check_call(
[
"ansible-playbook",
"-vv",
"openstack/playbooks/deploy.yaml",
"-i",
"openstack/inventory/openstack.yaml",
"-e",
"prefix=%s" % args.prefix,
]
)
subprocess.check_call(
[
"ansible-playbook",
"playbooks/prepare_datastore.yaml",
"-i",
"openstack/inventory/openstack.yaml",
"-vv",
]
)
subprocess.check_call(
[
"ansible-playbook",
"playbooks/write_inventory.yaml",
"-i",
"openstack/inventory/openstack.yaml",
"-vv",
]
)
if args.run_test:
subprocess.check_call(
[
"ansible-playbook",
"-vv",
"playbooks/run_test.yaml",
"-i",
"openstack/inventory/openstack.yaml",
"-e",
"prefix=%s" % args.prefix,
]
)
class DriverLibvirt:
@staticmethod
def cleanup(args):
for i in ["esxi1", "esxi2", "vcenter", "datastore"]:
subprocess.check_call(["vl", "stop", i])
@staticmethod
def purge(args):
subprocess.check_call(["vl", "down"])
@staticmethod
def deploy(args):
# prepare virt lightning configuration
cmd = []
cmd.append("ansible-playbook")
cmd.append("libvirt/playbooks/prepare_virt_lightning.yaml")
cmd.extend(
[
'-e "{}_distro={}"'.format(k, vars(args)[k])
for k in ("datastore", "esxi", "vcenter")
if vars(args)[k] is not None
]
)
cmd.append("-vv")
subprocess.check_call(cmd)
# create virt lightning vm
subprocess.check_call(
["vl", "up", "--virt-lightning-yaml", "libvirt/virt-lightning.yaml"]
)
# download zuul useful roles
cmd = []
cmd.append("ansible-playbook")
cmd.append("playbooks/download_zuul_ci_roles.yaml")
cmd.append("-vv")
subprocess.check_call(cmd)
# create ansible inventory
subprocess.check_call("vl ansible_inventory>inventory", shell=True)
# unset any ANSIBLE_ROLES_PATH variable to read the ansible.cfg file
if "ANSIBLE_ROLES_PATH" in os.environ:
del os.environ["ANSIBLE_ROLES_PATH"]
# prepare datastore
subprocess.check_call(
[
"ansible-playbook",
"playbooks/prepare_datastore.yaml",
"-i",
"inventory",
"-vv",
]
)
subprocess.check_call(
[
"ansible-playbook",
"playbooks/write_inventory.yaml",
"-i",
"inventory",
"-vv",
]
)
if args.run_test:
subprocess.check_call(
[
"ansible-playbook",
"-vv",
"playbooks/run_test.yaml",
"-i",
"inventory",
"-e",
"prefix=%s" % args.prefix,
]
)
parser = argparse.ArgumentParser(description="Process some integers.")
actions = {
"deploy": "Deploy the environment.",
"cleanup": "Remove the ESXi VMs and the VCenter, preserver the datastore.",
"purge": "Remove all the resources.",
}
help_actions = ", ".join(["🔥{k}: {v}".format(k=k, v=v) for k, v in actions.items()])
parser.add_argument(
"action", type=str, choices=actions.keys(), metavar=None, help=help_actions
)
parser.add_argument(
"--driver",
dest="driver",
type=str,
choices=["libvirt", "openstack"],
default="libvirt",
help="Driver to use",
)
parser.add_argument("--prefix", type=str, default="")
parser.add_argument("--run-test", type=bool, default=False)
parser.add_argument("--datastore-distro", type=str, dest="datastore")
parser.add_argument("--esxi-distro", type=str, dest="esxi")
parser.add_argument("--vcenter-distro", type=str, dest="vcenter")
args = parser.parse_args()
if args.driver == "openstack":
driver = DriverOpenStack
elif args.driver == "libvirt":
driver = DriverLibvirt
getattr(driver, args.action)(args)