aboutsummaryrefslogtreecommitdiffstats
path: root/templating/README.md
blob: 89f472efb13354606c47030ce6a46f251cd0ecbb (plain)
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
# Templating Engine

This engine does the templating for The Gathering.

The flask server sits behind varnish and waits for incomming GET requests with a template name and optional variables.

```varnish
backend templating {
    .host = "::1";
    .port = "8081";
}
....
if (req.url ~ "^/api/templates") {
    set req.url = regsub(req.url,"^/api/templates","");
    set req.backend_hint = templating;
}
```

## Requirements

* Python3.6
* jinja2
* requests
* flask
* netaddr

## Settings

```
python3 templating.py
usage: templating.py [-t TEMPLATES [TEMPLATES ...]] [-h HOST] [-p PORT] [-d]
                     [-s SERVER] [-x TIMEOUT]

Process templates for gondul.

optional arguments:
  -t TEMPLATES [TEMPLATES ...], --templates TEMPLATES [TEMPLATES ...]
                        location of templates
  -h HOST, --host HOST  host address
  -p PORT, --port PORT  host port
  -d, --debug           enable debug mode
  -s SERVER, --server SERVER
                        gondul server address
  -x TIMEOUT, --timeout TIMEOUT
                        gondul server timeout
```

## How to test locally

You need a directory with all the jinja2 templates. I just assume you git cloned the entire gondul repo.

An example using [test.conf](../web/templates/test.conf)

```bash
python3 templating.py --host ::1 --port 8081 --templates ../web/templates --server http://tech:rules@<gondul>:80
```

```bash
curl -s "http://[::1]:8081/test.conf?switch=e1-1" | jq .
{
  "distro_name": "core-dev",
  "placement": {
    "height": 20,
    "width": 250,
    "x": "830",
    "y": "620"
  },
  "tags": []
}
```