From dd1888d2b91ca4570a6356303d2e18189a92f590 Mon Sep 17 00:00:00 2001 From: Dobli <61doal1mst@hft-stuttgart.de> Date: Wed, 13 Feb 2019 11:50:46 +0100 Subject: [PATCH] fully replaced service dict with enum class --- building_manager.py | 41 +++++++++------------------ template_configs/docker-templates.yml | 2 +- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/building_manager.py b/building_manager.py index 09490e6..4b4b0e0 100755 --- a/building_manager.py +++ b/building_manager.py @@ -62,17 +62,6 @@ EDIT_FILES = { "pb_framr_pages": "pb-framr/pages.json" } CONSTRAINTS = {"building": "node.labels.building"} -SERVICES = { - "sftp": "sftp", - "openhab": "openhab", - "nodered": "nodered", - "postgres": "postgres", - "mqtt": "mqtt" -} -FRONTEND_SERVICES = { - "openhab": "OpenHAB", - "nodered": "Node-RED" -} # Default Swarm port SWARM_PORT = 2377 @@ -83,18 +72,16 @@ ADMIN_USER = 'ohadmin' class Service(Enum): - SFTP = ("SFTP", "sftp_X", False) - OPENHAB = ("OpenHAB", "openhab_X", True, '/', 'dashboard') - NODERED = ("Node-RED", "nodered_X", True, 'nodered', 'ballot') - POSTGRES = ("Postgre SQL", "postgres_X", False) - MQTT = ("Mosquitto MQTT Broker", "mqtt_X", False) - - def __init__(self, fullname, compose_entry, frontend, - prefix=None, icon=None): + SFTP = ("SFTP", "sftp", False) + OPENHAB = ("OpenHAB", "openhab", True, 'dashboard') + NODERED = ("Node-RED", "nodered", True, 'ballot') + POSTGRES = ("Postgre SQL", "postgres", False) + MQTT = ("Mosquitto MQTT Broker", "mqtt", False) + + def __init__(self, fullname, prefix, frontend, icon=None): self.fullname = fullname - self.compose_entry = compose_entry - self.frontend = frontend self.prefix = prefix + self.frontend = frontend self.icon = icon # >>> @@ -132,7 +119,7 @@ def add_sftp_service(base_dir, hostname, number=0): # service name service_name = f'sftp_{hostname}' # template - template = get_service_template(base_dir, SERVICES['sftp']) + template = get_service_template(base_dir, Service.SFTP.prefix) # only label contraint is building template['deploy']['placement']['constraints'][0] = ( f"{CONSTRAINTS['building']} == {hostname}") @@ -153,7 +140,7 @@ def add_openhab_service(base_dir, hostname): # service name service_name = f'openhab_{hostname}' # template - template = get_service_template(base_dir, SERVICES['openhab']) + template = get_service_template(base_dir, Service.OPENHAB.prefix) # only label contraint is building template['deploy']['placement']['constraints'][0] = ( f"{CONSTRAINTS['building']} == {hostname}") @@ -185,7 +172,7 @@ def add_nodered_service(base_dir, hostname): # service name service_name = f'nodered_{hostname}' # template - template = get_service_template(base_dir, SERVICES['nodered']) + template = get_service_template(base_dir, Service.NODERED.prefix) # only label contraint is building template['deploy']['placement']['constraints'][0] = ( f"{CONSTRAINTS['building']} == {hostname}") @@ -212,7 +199,7 @@ def add_mqtt_service(base_dir, hostname, number=0): # service name service_name = f'mqtt_{hostname}' # template - template = get_service_template(base_dir, SERVICES['mqtt']) + template = get_service_template(base_dir, Service.MQTT.prefix) # only label contraint is building template['deploy']['placement']['constraints'][0] = ( f"{CONSTRAINTS['building']} == {hostname}") @@ -234,7 +221,7 @@ def add_postgres_service(base_dir, hostname): # service name service_name = f'postgres_{hostname}' # template - template = get_service_template(base_dir, SERVICES['postgres']) + template = get_service_template(base_dir, Service.POSTGRES.prefix) # only label contraint is building template['deploy']['placement']['constraints'][0] = ( f"{CONSTRAINTS['building']} == {hostname}") @@ -432,7 +419,7 @@ def generate_pb_framr_entry(host, service): """ entry = {} entry['title'] = service.fullname - if service.prefix == "/": + if service == Service.OPENHAB: entry['url'] = f'http://{host}/' pass else: diff --git a/template_configs/docker-templates.yml b/template_configs/docker-templates.yml index 389f285..9324e95 100644 --- a/template_configs/docker-templates.yml +++ b/template_configs/docker-templates.yml @@ -65,7 +65,7 @@ services: - "backup_cache:/volumerize-cache" - "backup_data:/backup" configs: - - source: backup_config_X + - source: backup_config target: /backup_config.json - source: sftp_id_key target: /root/.ssh/id_rsa -- GitLab