~landscape/landscape-bundles/trunk

9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
1
#!/usr/bin/python3
25.1.3 by Bjorn Tillenius
Review comments.
2
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
3
"""Render the landscape-server bundles."""
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
4
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
5
import argparse
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
6
import os
24.1.2 by David Britton
remove rendered bundles, add .bzrignore, Makefile render change
7
import shutil
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
8
9
from jinja2 import FileSystemLoader, Environment
10
11
DEFAULTS = {
12
    "rabbitmq": {},
13
    "postgresql": {
14
        "max_connections": 500,
12 by Andreas Hasenack
Merged with the new bundles for the release of LDS 15.10 with the new charm
15
        "max_prepared_transactions": 500,
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
16
        "memory": 2048},
17
    "haproxy": {},
18
    "landscape": {
55.1.1 by Simon Poirier
Bump landscape-server charm revision and properly quote charm-store script.
19
        "charm": "cs:bionic/landscape-server-40",
50.1.1 by Nobuto Murata
Bump landscape-server's mem contraint to 4096
20
        "memory": 4096,
45.1.1 by Adam Collard
Update to install_sources version
21
        # We defer to the default "install_sources" from the charm.
22
        "install_keys": "4652B4E6"}
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
23
}
24
25
FLAVORS = [
26
    # scalable
27
    {"name": "scalable"},
28
29
    # dense
30
    {"name": "dense",
31
     "rabbitmq": {
38.1.1 by David Britton
- s/lxc/lxd/
32
         "to": "lxd:0"},
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
33
     "postgresql": {
38.1.1 by David Britton
- s/lxc/lxd/
34
         "to": "lxd:0"},
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
35
     "haproxy": {
36
         "to": "0"},
37
     "landscape": {
38.1.1 by David Britton
- s/lxc/lxd/
38
         "to": "lxd:0"}},
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
39
40
    # dense-maas
41
    {"name": "dense-maas",
42
     "rabbitmq": {
38.1.1 by David Britton
- s/lxc/lxd/
43
         "to": "lxd:0"},
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
44
     "postgresql": {
38.1.1 by David Britton
- s/lxc/lxd/
45
         "to": "lxd:0"},
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
46
     "haproxy": {
38.1.1 by David Britton
- s/lxc/lxd/
47
         "to": "lxd:0"},
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
48
     "landscape": {
38.1.1 by David Britton
- s/lxc/lxd/
49
         "to": "lxd:0"}},
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
50
]
51
52
if __name__ == "__main__":
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
53
    current_dir = os.path.dirname(__file__)
54
    parser = argparse.ArgumentParser(description=__doc__)
25.1.2 by Bjorn Tillenius
Allow the landscape-server branch to specified to render-bundles.
55
    parser.add_argument("--landscape-branch", type=str, required=False)
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
56
    parser.add_argument("--landscape-charm", type=str, required=False)
57
    args = parser.parse_args()
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
58
    environment = Environment(
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
59
        loader=FileSystemLoader(current_dir),
60
        trim_blocks=True, lstrip_blocks=True,
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
61
        keep_trailing_newline=True)
62
    template = environment.get_template("landscape-template.jinja2")
63
    for flavor in FLAVORS:
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
64
        build_dir = os.path.join(current_dir, "build")
65
        path_parts = [build_dir, "landscape-%s" % flavor["name"]]
24.1.2 by David Britton
remove rendered bundles, add .bzrignore, Makefile render change
66
        os.makedirs(os.path.join(*path_parts))
67
        shutil.copy("README.md", os.path.join(*path_parts))
68
69
        path_parts.append("bundle.yaml")
70
        with open(os.path.join(*path_parts), "w") as fd:
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
71
            context = DEFAULTS.copy()
25.1.3 by Bjorn Tillenius
Review comments.
72
            for key in context:
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
73
                context[key].update(flavor.get(key, {}))
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
74
            context["name"] = flavor["name"]
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
75
            if args.landscape_charm:
76
                context["landscape"]["charm"] = args.landscape_charm
25.1.2 by Bjorn Tillenius
Allow the landscape-server branch to specified to render-bundles.
77
            if args.landscape_branch:
78
                context["landscape"]["branch"] = args.landscape_branch
9.1.8 by Free Ekanayaka
Generate bundles from a template [trivial] [r=adam-collard]
79
            fd.write(template.render(context))
25.1.1 by Bjorn Tillenius
Allow the landscape-server charm to specified to render-bundles.
80
    print("Generated bundles in {}/...".format(build_dir))