diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-11-07 20:15:26 +0100 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-11-07 20:15:26 +0100 |
commit | 1645bca3aed66c2121fe6d8aaeea8405906723e2 (patch) | |
tree | b4c00cde77a2bbc8255d1b295b962b14926889ac | |
parent | fc1b028e555a3703fbc643965620dea919f3fe19 (diff) |
Scaffolding for functional templating :D
-rw-r--r-- | ansible/playbook-test.yml | 6 | ||||
-rw-r--r-- | build/test/gondul-templating-test.Dockerfile | 10 | ||||
-rw-r--r-- | extras/misc/varnish.vcl | 9 | ||||
-rwxr-xr-x | templating/templating.py | 6 |
4 files changed, 27 insertions, 4 deletions
diff --git a/ansible/playbook-test.yml b/ansible/playbook-test.yml index ee35b04..7295395 100644 --- a/ansible/playbook-test.yml +++ b/ansible/playbook-test.yml @@ -26,9 +26,13 @@ volumes: [ "{{ pwd.stdout }}/:/opt/gondul" ] links: [ "gondul-db-test:db" ] ports: "{{ front_ports }}" + - name: "gondul-templating-test" + volumes: [ "{{ pwd.stdout }}/:/opt/gondul" ] + links: [ "gondul-front-test:gondul-front"] + ports: [] - name: "gondul-varnish-test" volumes: [ "{{ pwd.stdout }}/:/opt/gondul" ] - links: [ "gondul-front-test:gondul-front", "gondul-graphite-test:gondul-graphite" ] + links: [ "gondul-front-test:gondul-front", "gondul-graphite-test:gondul-graphite", "gondul-templating-test:gondul-templating" ] ports: "{{ varnish_ports }}" - name: "gondul-snmp-test" volumes: [ "{{ pwd.stdout }}/:/opt/gondul" ] diff --git a/build/test/gondul-templating-test.Dockerfile b/build/test/gondul-templating-test.Dockerfile new file mode 100644 index 0000000..80c09c0 --- /dev/null +++ b/build/test/gondul-templating-test.Dockerfile @@ -0,0 +1,10 @@ +FROM debian:jessie +RUN apt-get update +RUN apt-get -y install \ + python3-jinja2 \ + python3-requests + +RUN mkdir -p /opt/gondul + +CMD /opt/gondul/templating/templating.py +EXPOSE 8080 diff --git a/extras/misc/varnish.vcl b/extras/misc/varnish.vcl index b10a640..c9e23c5 100644 --- a/extras/misc/varnish.vcl +++ b/extras/misc/varnish.vcl @@ -12,6 +12,11 @@ backend graphite { .port = "80"; } +backend templating { + .host = "gondul-templating"; + .port = "8080"; +} + sub vcl_recv { if (req.url ~ "^/where" || req.url ~ "^/location") { set req.url = "/api/public/location"; @@ -35,6 +40,10 @@ sub vcl_recv { if (req.url ~ "/render") { set req.backend_hint = graphite; } + if (req.url ~ "/templating") { + set req.url = regsub(req.url, "/templating", ""); + set req.backend_hint = templating; + } # Brukes ikke. Cookies er for nubs. unset req.http.Cookie; diff --git a/templating/templating.py b/templating/templating.py index 47c886d..2c1259a 100755 --- a/templating/templating.py +++ b/templating/templating.py @@ -8,7 +8,7 @@ endpoints = "read/oplog read/snmp read/switches-management public/config public/ objects = dict() def getEndpoint(endpoint): - r = requests.get("http://localhost/api/%s" % endpoint, auth=('demo','demo')) + r = requests.get("http://gondul-front:/api/%s" % endpoint, auth=('demo','demo')) if (r.status_code != 200): raise Exception("Bad status code for endpoint %s: %s" % (endpoint, r.status_code)) return r.json() @@ -17,7 +17,7 @@ def updateData(): for a in endpoints: objects[a] = getEndpoint(a) -env = Environment(loader=FileSystemLoader('templates/')) +env = Environment(loader=FileSystemLoader(['templates/','/opt/gondul/templating/templates'])) import http.server class MyHandler(http.server.BaseHTTPRequestHandler): @@ -38,7 +38,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler): self.wfile.flush() def run(server_class=http.server.HTTPServer, handler_class=http.server.BaseHTTPRequestHandler): - server_address = ('', 8000) + server_address = ('', 8080) httpd = server_class(server_address, handler_class) httpd.serve_forever() |