summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/views.py68
1 files changed, 63 insertions, 5 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 72a8b14..1beaa5b 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -569,12 +569,12 @@ def action_poweroff():
payload = {'clients': ips}
server = get_server_from_clients(ips)
r = server.post('/poweroff', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- flash(_('ogServer: error powering off client'),
- category='error')
- else:
- flash(_('Client powered off successfully'),
- category='info')
+ return ogserver_error('commands')
+
+ flash(_('Client powered off successfully'), category='info')
return redirect(url_for('commands'))
else:
ips = parse_elements(request.args.to_dict())
@@ -773,6 +773,8 @@ def action_setup_modify():
server = get_server_from_clients(list(ips))
r = server.post('/setup', payload=payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
return redirect(url_for('commands'))
flash(_(f'Invalid setup form'), category='error')
@@ -920,6 +922,8 @@ def action_image_restore():
'profile': str(image['software_id']),
'id': str(image['id'])}
server.post('/image/restore', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
flash(_(f'Image restore command sent sucessfully'), category='info')
else:
@@ -1033,6 +1037,8 @@ def action_hardware():
ips = form.ips.data.split(' ')
server = get_server_from_clients(ips)
r = server.post('/hardware', payload={'clients': ips})
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
flash(_(f'Hardware inventory command has been sent'), category='info')
else:
@@ -1081,6 +1087,8 @@ def action_software():
r = server.post('/software', payload={'clients': ips,
'disk': disk,
'partition': partition})
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
flash(_('Software profile request sent successfully'), category='info')
else:
@@ -1147,6 +1155,8 @@ def action_session():
r = server.post('/session', payload={'clients': valid_ips,
'disk': str(disk),
'partition': str(partition)})
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
if excluded_ips:
flash('The following clients didn\'t match the boot configuration: ' + str(excluded_ips))
@@ -1218,6 +1228,8 @@ def action_client_cache():
r = server.post('/cache/delete',
payload={'clients': client_list,
'images': image_list})
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
flash(_('Cache delete request sent successfully'), category='info')
else:
@@ -1411,6 +1423,8 @@ def action_client_update():
"mac": mac_address }
server = get_server_from_ip_port(form.server.data)
r = server.post('/client/update', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error updating client'),
category='error')
@@ -1535,6 +1549,8 @@ def action_folder_delete():
payload = {"id": int(form.folder_id.data)}
server = get_server_from_ip_port(form.server.data)
r = server.post('/folder/delete', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error deleting folder'),
category='error')
@@ -1568,6 +1584,8 @@ def action_folder_update():
server = get_server_from_ip_port(form.server.data)
r = server.post('/folder/update', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error updating folder'),
category='error')
@@ -1626,6 +1644,8 @@ def action_folder_add_post():
server = get_server_from_ip_port(form.server.data)
r = server.post('/folder/add', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error adding folder'),
category='error')
@@ -1676,6 +1696,8 @@ def action_client_add():
server = get_server_from_ip_port(form.server.data)
r = server.post('/client/add', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error adding client'),
category='error')
@@ -1769,6 +1791,8 @@ def action_client_move():
"folder_id": int(folder_id)}
server = get_server_from_clients(ips)
r = server.post('/client/move', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error moving client'),
category='error')
@@ -1929,6 +1953,8 @@ def action_client_delete():
payload = {'clients': ips}
server = get_server_from_clients(ips)
r = server.post('/client/delete', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error deleting client'),
category='error')
@@ -2086,6 +2112,8 @@ def action_mode():
server = get_server_from_clients(ips)
r = server.post('/mode', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
flash(_('Client set boot mode request sent successfully'), category='info')
else:
@@ -2170,6 +2198,8 @@ def action_oglive():
payload = {'clients': ips, 'name': form.oglive.data}
server = get_server_from_clients(ips)
r = server.post('/oglive/set', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
flash(_('Client set ogLive request sent successfully'),
category='info')
@@ -2248,6 +2278,8 @@ def action_image_create():
"group_id": 0, # Default group.
"center_id": r.json()["center"]}
r = server.post('/image/create', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
return redirect(url_for('commands'))
return make_response("400 Bad Request", 400)
@@ -2340,6 +2372,8 @@ def action_image_update():
'group_id': 0,
'center_id': 0}
r = server.post('/image/update', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code == requests.codes.ok:
flash(_('Image update command sent sucessfully'), category='info')
else:
@@ -2431,6 +2465,8 @@ def action_reboot():
payload = {'clients': ips}
server = get_server_from_clients(ips)
r = server.post('/reboot', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error rebooting client'),
category='error')
@@ -2461,6 +2497,8 @@ def action_refresh():
server = get_server_from_clients(list(ips))
payload = {'clients': list(ips)}
r = server.post('/refresh', payload)
+ if not r:
+ return ogserver_down('commands')
if r.status_code != requests.codes.ok:
flash(_('OgServer replied with a non ok status code'), category='error')
else:
@@ -2476,6 +2514,8 @@ def action_center_add():
"comment": form.comment.data}
server = get_server_from_ip_port(form.server.data)
r = server.post('/center/add', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('Server replied with error code when adding the center'),
category='error')
@@ -2500,6 +2540,8 @@ def action_center_update():
"comment": form.comment.data}
server = get_server_from_ip_port(form.server.data)
r = server.post('/center/update', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('Server replied with error code when updating the center'),
category='error')
@@ -2618,6 +2660,8 @@ def action_center_delete():
server = get_server_from_ip_port(form.server.data)
payload = {"id": form.center.data}
r = server.post('/center/delete', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('Server replied with error code when deleting the center'),
category='error')
@@ -2655,6 +2699,8 @@ def action_room_add():
"gateway": form.gateway.data,
"folder_id": int(form.folder_id.data)}
r = server.post('/room/add', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('Server replied with error code when adding the room'), category='error')
else:
@@ -2700,6 +2746,8 @@ def action_room_update():
"gateway": form.gateway.data,
"id": int(form.room.data)}
r = server.post('/room/update', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('Server replied with error code when updating the room'), category='error')
else:
@@ -2773,6 +2821,8 @@ def action_room_delete():
payload = {"id": form.room.data}
server = get_server_from_ip_port(form.server.data)
r = server.post('/room/delete', payload)
+ if not r:
+ return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
flash(_('Server replied with error code when deleting the room'),
category='error')
@@ -2863,6 +2913,8 @@ def action_repo_add():
"center": 1}
server = get_server_from_ip_port(form.server.data)
r = server.post('/repository/add', payload)
+ if not r:
+ return ogserver_down('manage_repos')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error adding repo'),
category='error')
@@ -2892,6 +2944,8 @@ def action_repo_update():
'ip': form.ip.data,
'center': 1}
r = server.post('/repository/update', payload)
+ if not r:
+ return ogserver_down('manage_repos')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error updating repo'),
category='error')
@@ -2935,6 +2989,8 @@ def action_repo_delete():
server = get_server_from_ip_port(form.server.data)
payload = { 'id': form.repo_id.data }
r = server.post('/repository/delete', payload)
+ if not r:
+ return ogserver_down('manage_repos')
if r.status_code != requests.codes.ok:
flash(_('ogServer: error deleting repo'),
category='error')
@@ -3499,6 +3555,8 @@ def action_image_delete():
payload = {'image': id}
server = get_server_from_ip_port(form.server.data)
r = server.post('/image/delete', payload)
+ if not r:
+ return ogserver_down('images')
if r.status_code != requests.codes.ok:
flash(_('OgServer replied with a non ok status code'), category='error')
else: