Skip to content

Commit 04dd5da

Browse files
committed
Improved error handling when vpn host not created
1 parent 3a579bc commit 04dd5da

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

app/playbook.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,18 @@ def _process_block(b):
186186

187187
display.display(taskmsg)
188188

189-
host = inventory.groups['vpn-host'].hosts[0].name
190-
host_vars = variable_manager.get_vars()['hostvars'][host]
191-
return {
192-
'CA_password': host_vars.get('CA_password'),
193-
'p12_export_password': host_vars.get('p12_export_password'),
194-
'algo_server_name': host_vars.get('server_name'),
195-
'ipv6_support': host_vars.get('ipv6_support'),
196-
'local_service_ip': host_vars.get('ansible_lo') and
197-
host_vars.get('ansible_lo').get('ipv4_secondaries') and
198-
host_vars.get('ansible_lo').get('ipv4_secondaries')[0]['address'],
199-
'ansible_ssh_host': host,
200-
}
189+
if 'vpn-host' not in inventory.groups:
190+
raise ValueError('no_vpn_host')
191+
else:
192+
host = inventory.groups['vpn-host'].hosts[0].name
193+
host_vars = variable_manager.get_vars()['hostvars'][host]
194+
return {
195+
'CA_password': host_vars.get('CA_password'),
196+
'p12_export_password': host_vars.get('p12_export_password'),
197+
'algo_server_name': host_vars.get('server_name'),
198+
'ipv6_support': host_vars.get('ipv6_support'),
199+
'local_service_ip': host_vars.get('ansible_lo') and
200+
host_vars.get('ansible_lo').get('ipv4_secondaries') and
201+
host_vars.get('ansible_lo').get('ipv4_secondaries')[0]['address'],
202+
'ansible_ssh_host': host,
203+
}

app/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ async def playbook_get_handler(request):
4040
return web.json_response({'status': None})
4141

4242
if task_future.done():
43-
return web.json_response({'status': 'done', 'program': task_program, 'result': task_future.result()})
43+
try:
44+
return web.json_response({'status': 'done', 'program': task_program, 'result': task_future.result()})
45+
except ValueError as e:
46+
return web.json_response({'status': 'error', 'program': task_program, 'result': str(e)})
4447
elif task_future.cancelled():
4548
return web.json_response({'status': 'cancelled', 'program': task_program})
4649
else:

app/static/provider-scaleway.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
v-bind:disabled="ui_loading_check || ui_token_from_env"
2121
v-model="scaleway_token"
2222
/>
23-
<p v-if="ui_token_from_env">Token was read from the environment</p>
23+
<div v-if="ui_token_from_env" class="form-text alert alert-success" role="alert">
24+
Token was read from the environment variable
25+
</div>
2426
</div>
2527

2628
<div class="form-group">

app/static/provider-vultr.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
v-bind:disabled="ui_loading_check"
2121
v-model="vultr_config"
2222
/>
23+
<div v-if="ui_token_from_env" class="form-text alert alert-success" role="alert">
24+
Configuration file was found in your system. You still can change the path to it
25+
</div>
2326
</div>
2427

2528
<div class="form-group">
@@ -47,6 +50,7 @@ module.exports = {
4750
vultr_config: null,
4851
region: null,
4952
// helper variables
53+
ui_token_from_env: false,
5054
ui_loading_check: false,
5155
ui_loading_regions: false,
5256
ui_region_options: []
@@ -69,6 +73,7 @@ module.exports = {
6973
.then(response => {
7074
if (response.path) {
7175
this.vultr_config = response.path;
76+
this.ui_token_from_env = true;
7277
}
7378
})
7479
.finally(() => {

0 commit comments

Comments
 (0)