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
|
#!/usr/bin/python3
"""Render the landscape-server bundles."""
import argparse
import os
import shutil
from jinja2 import FileSystemLoader, Environment
DEFAULTS = {
"rabbitmq": {},
"postgresql": {
"max_connections": 500,
"max_prepared_transactions": 500,
"memory": 2048},
"haproxy": {},
"landscape": {
"charm": "cs:bionic/landscape-server-30",
"memory": 2048,
# We defer to the default "install_sources" from the charm.
"install_keys": "4652B4E6"}
}
FLAVORS = [
# scalable
{"name": "scalable"},
# dense
{"name": "dense",
"rabbitmq": {
"to": "lxd:0"},
"postgresql": {
"to": "lxd:0"},
"haproxy": {
"to": "0"},
"landscape": {
"to": "lxd:0"}},
# dense-maas
{"name": "dense-maas",
"rabbitmq": {
"to": "lxd:0"},
"postgresql": {
"to": "lxd:0"},
"haproxy": {
"to": "lxd:0"},
"landscape": {
"to": "lxd:0"}},
]
if __name__ == "__main__":
current_dir = os.path.dirname(__file__)
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--landscape-branch", type=str, required=False)
parser.add_argument("--landscape-charm", type=str, required=False)
args = parser.parse_args()
environment = Environment(
loader=FileSystemLoader(current_dir),
trim_blocks=True, lstrip_blocks=True,
keep_trailing_newline=True)
template = environment.get_template("landscape-template.jinja2")
for flavor in FLAVORS:
build_dir = os.path.join(current_dir, "build")
path_parts = [build_dir, "landscape-%s" % flavor["name"]]
os.makedirs(os.path.join(*path_parts))
shutil.copy("README.md", os.path.join(*path_parts))
path_parts.append("bundle.yaml")
with open(os.path.join(*path_parts), "w") as fd:
context = DEFAULTS.copy()
for key in context:
context[key].update(flavor.get(key, {}))
context["name"] = flavor["name"]
if args.landscape_charm:
context["landscape"]["charm"] = args.landscape_charm
if args.landscape_branch:
context["landscape"]["branch"] = args.landscape_branch
fd.write(template.render(context))
print("Generated bundles in {}/...".format(build_dir))
|