Commit 12557efd authored by Daniele Venzano's avatar Daniele Venzano

Test traefik integration and fix a few bugs

parent 548c234e
......@@ -210,10 +210,10 @@ class APIEndpoint:
for port in service.ports:
if port.external_ip is not None:
endpoint = port.url_template.format(**{"ip_port": port.external_ip + ":" + str(port.external_port)})
if zoe_lib.config.get_conf().traefik_zk_ips is None:
if zoe_lib.config.get_conf().traefik_zk_ips is None or not port.enable_proxy:
endpoint_ext = None
else:
endpoint_ext = '/{}/{}'.format(zoe_lib.config.get_conf().traefik_base_url, port.proxy_key())
endpoint_ext = '{}/{}'.format(zoe_lib.config.get_conf().traefik_base_url, port.proxy_key())
endpoints.append((port.readable_name, endpoint, endpoint_ext))
return services_info, endpoints
......
......@@ -124,11 +124,12 @@ class Execution(BaseRecord):
zk.start()
for service in self.services:
for port in service.ports:
endpoint = port.url_template.format(**{"ip_port": port.external_ip + ":" + str(port.external_port)})
if port.enable_proxy:
endpoint = port.url_template.format(**{"ip_port": port.external_ip + ":" + str(port.external_port)}).encode('utf-8')
traefik_name = 'zoe_exec_{}_{}'.format(self.id, port.id)
zk.create('/traefik/backends/{}/servers/server/url'.format(traefik_name), endpoint, makepath=True)
zk.create('/traefik/frontends/{}/routes/path/rule'.format(traefik_name), 'PathPrefix:{}/{}'.format(zoe_lib.config.get_conf().traefik_base_url, port.proxy_key()), makepath=True)
zk.create('/traefik/frontends/{}/backend'.format(traefik_name), traefik_name, makepath=True)
zk.create('/traefik/frontends/{}/routes/path/rule'.format(traefik_name), 'PathPrefix:{}/{}'.format(zoe_lib.config.get_conf().traefik_base_url, port.proxy_key()).encode('utf-8'), makepath=True)
zk.create('/traefik/frontends/{}/backend'.format(traefik_name), traefik_name.encode('utf-8'), makepath=True)
zk.create('/traefik/alias')
zk.delete('/traefik/alias')
zk.stop()
......@@ -141,8 +142,12 @@ class Execution(BaseRecord):
if zoe_lib.config.get_conf().traefik_zk_ips is not None:
zk = KazooClient(hosts=zoe_lib.config.get_conf().traefik_zk_ips)
zk.start()
zk.delete('/traefik/backends/zoe_exec_{}', recursive=True)
zk.delete('/traefik/frontends/zoetest', recursive=True)
for service in self.services:
for port in service.ports:
if port.enable_proxy:
traefik_name = 'zoe_exec_{}_{}'.format(self.id, port.id)
zk.delete('/traefik/backends/{}'.format(traefik_name), recursive=True)
zk.delete('/traefik/frontends/{}'.format(traefik_name), recursive=True)
zk.create('/traefik/alias')
zk.delete('/traefik/alias')
zk.stop()
......
......@@ -39,6 +39,10 @@ class Port(BaseRecord):
self.protocol = self.description['protocol']
self.url_template = self.description['url_template']
self.readable_name = self.description['name']
if 'proxy' in self.description:
self.enable_proxy = self.description['proxy']
else:
self.enable_proxy = False
def serialize(self):
"""Generates a dictionary that can be serialized in JSON."""
......@@ -67,7 +71,7 @@ class Port(BaseRecord):
def proxy_key(self):
"""Return unique identifier that can be used ti generate proxy URLs."""
return hashlib.sha256("{}:{}".format(self.id, zoe_lib.config.get_conf().cookie_secret)).hexdigest()
return hashlib.sha256("{}:{}".format(self.id, zoe_lib.config.get_conf().cookie_secret).encode('utf-8')).hexdigest()
class PortTable(BaseTable):
......
......@@ -56,6 +56,7 @@ def main(test_conf=None):
if args.log_file != "stderr":
log_args['filename'] = args.log_file
logging.basicConfig(**log_args)
# logging.getLogger("kazoo").setLevel(logging.WARNING)
ret = _check_configuration_sanity()
if ret != 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment