From 571e6417878a3cb1e7e1e41f2cb3d43cea0d21b7 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sat, 4 Apr 2020 13:38:03 +0200 Subject: [PATCH] Add proxy registration/unregistration --- usr/lib/python3.8/vmmgr/templates.py | 2 +- usr/lib/python3.8/vmmgr/vmmgr.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/usr/lib/python3.8/vmmgr/templates.py b/usr/lib/python3.8/vmmgr/templates.py index 70195a6..079cf25 100644 --- a/usr/lib/python3.8/vmmgr/templates.py +++ b/usr/lib/python3.8/vmmgr/templates.py @@ -8,7 +8,7 @@ NGINX = '''server {{ error_log /var/log/nginx/{app}.error.log; location / {{ - proxy_pass http://{app}:8080; + proxy_pass http://{ip}:8080; }} error_page 502 /502.html; diff --git a/usr/lib/python3.8/vmmgr/vmmgr.py b/usr/lib/python3.8/vmmgr/vmmgr.py index a98b95b..dc4fe59 100644 --- a/usr/lib/python3.8/vmmgr/vmmgr.py +++ b/usr/lib/python3.8/vmmgr/vmmgr.py @@ -6,7 +6,7 @@ import os import shutil import subprocess import urllib -from spoc import config as spoc_config, repo_local, repo_online +from spoc import config as spoc_config, net as spoc_net, repo_local, repo_online from spoc.app import App from spoc.container import Container, ContainerState from spoc.depsolver import DepSolver @@ -23,16 +23,20 @@ def register_app(app, host, login, password): 'password': password if password else 'N/A', 'visible': False, }) + register_proxy(app) def unregister_app(app): + unregister_proxy(app) config.unregister_app(app) def register_proxy(app): # Setup proxy configuration and reload nginx app_host = config.get_apps()[app]['host'] host = config.get_host() + # Assume that the main container has always the same name as the app + app_ip = spoc_net.get_ip(app) with open(os.path.join(NGINX_DIR, f'{app}.conf'), 'w') as f: - f.write(templates.NGINX.format(app=app, host=app_host, domain=host['domain'], port=host['port'])) + f.write(templates.NGINX.format(app=app, host=app_host, ip=app_ip, domain=host['domain'], port=host['port'])) reload_nginx() def unregister_proxy(app): @@ -146,7 +150,7 @@ def update_app_autostart(app_name, enabled): App(app_name, False).set_autostart(enabled) def is_app_started(app_name): - # Assume that the main container has always the same name as app + # Assume that the main container has always the same name as the app return Container(app_name).get_state() == ContainerState.RUNNING def is_app_autostarted(app_name):