From ca3230c0de76e7f97eb7433e0081dd998ac3e41b Mon Sep 17 00:00:00 2001 From: Ivan Gromov Date: Sun, 9 Aug 2020 00:55:21 +0500 Subject: [PATCH] Improved error handling when vpn host not created --- app/playbook.py | 27 +++++++++++++++------------ app/server.py | 5 ++++- app/static/provider-scaleway.vue | 4 +++- app/static/provider-vultr.vue | 5 +++++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/playbook.py b/app/playbook.py index a361cdb..2d4d3d0 100644 --- a/app/playbook.py +++ b/app/playbook.py @@ -186,15 +186,18 @@ class PlaybookCLI(CLI): display.display(taskmsg) - host = inventory.groups['vpn-host'].hosts[0].name - host_vars = variable_manager.get_vars()['hostvars'][host] - return { - 'CA_password': host_vars.get('CA_password'), - 'p12_export_password': host_vars.get('p12_export_password'), - 'algo_server_name': host_vars.get('server_name'), - 'ipv6_support': host_vars.get('ipv6_support'), - 'local_service_ip': host_vars.get('ansible_lo') and - host_vars.get('ansible_lo').get('ipv4_secondaries') and - host_vars.get('ansible_lo').get('ipv4_secondaries')[0]['address'], - 'ansible_ssh_host': host, - } + if 'vpn-host' not in inventory.groups: + raise ValueError('no_vpn_host') + else: + host = inventory.groups['vpn-host'].hosts[0].name + host_vars = variable_manager.get_vars()['hostvars'][host] + return { + 'CA_password': host_vars.get('CA_password'), + 'p12_export_password': host_vars.get('p12_export_password'), + 'algo_server_name': host_vars.get('server_name'), + 'ipv6_support': host_vars.get('ipv6_support'), + 'local_service_ip': host_vars.get('ansible_lo') and + host_vars.get('ansible_lo').get('ipv4_secondaries') and + host_vars.get('ansible_lo').get('ipv4_secondaries')[0]['address'], + 'ansible_ssh_host': host, + } diff --git a/app/server.py b/app/server.py index fe6c104..5eb134d 100644 --- a/app/server.py +++ b/app/server.py @@ -40,7 +40,10 @@ async def playbook_get_handler(request): return web.json_response({'status': None}) if task_future.done(): - return web.json_response({'status': 'done', 'program': task_program, 'result': task_future.result()}) + try: + return web.json_response({'status': 'done', 'program': task_program, 'result': task_future.result()}) + except ValueError as e: + return web.json_response({'status': 'error', 'program': task_program, 'result': str(e)}) elif task_future.cancelled(): return web.json_response({'status': 'cancelled', 'program': task_program}) else: diff --git a/app/static/provider-scaleway.vue b/app/static/provider-scaleway.vue index d8fcf73..d53f65d 100644 --- a/app/static/provider-scaleway.vue +++ b/app/static/provider-scaleway.vue @@ -20,7 +20,9 @@ v-bind:disabled="ui_loading_check || ui_token_from_env" v-model="scaleway_token" /> -

Token was read from the environment

+
diff --git a/app/static/provider-vultr.vue b/app/static/provider-vultr.vue index cb062c7..2d156db 100644 --- a/app/static/provider-vultr.vue +++ b/app/static/provider-vultr.vue @@ -20,6 +20,9 @@ v-bind:disabled="ui_loading_check" v-model="vultr_config" /> +
@@ -47,6 +50,7 @@ module.exports = { vultr_config: null, region: null, // helper variables + ui_token_from_env: false, ui_loading_check: false, ui_loading_regions: false, ui_region_options: [] @@ -69,6 +73,7 @@ module.exports = { .then(response => { if (response.path) { this.vultr_config = response.path; + this.ui_token_from_env = true; } }) .finally(() => {