-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen-vcl.py
44 lines (38 loc) · 1.24 KB
/
gen-vcl.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
#!/usr/bin/env python
from jinja2 import Template
import yaml
import sys
import os
from urlparse import urlparse
def _render(d):
with open(sys.argv[1]) as template:
t = Template(template.read())
print t.render(**d)
data = None
if len(sys.argv) == 3:
with open(sys.argv[2]) as config:
data = yaml.load(config.read())
elif 'BACKEND_PORT' in os.environ:
backend_uri = os.environ['BACKEND_PORT']
backend_uri = backend_uri.replace("tcp://","http://")
if not backend_uri.endswith("/"):
backend_uri = "%s/" % backend_uri
public_name = 'localhost'
backends=dict(backend=[backend_uri])
data = dict(domain='localdomain',vhosts=dict(),default_backend='backend')
if 'ACME_PORT' in os.environ:
acme_uri = os.environ['ACME_PORT']
acme_uri = acme_uri.replace("tcp://","http://")
if not acme_uri.endswith("/"):
acme_uri = "%s/" % acme_uri
backends['acme'] = [acme_uri]
data['acme_backend'] = 'acme'
data['backends'] = backends
else:
print "No linked applications and no config"
sys.exit(-1)
data['uris'] = dict()
for name,members in data['backends'].iteritems():
for member in members:
data['uris'][member] = urlparse(member)
_render(data)