summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-12-11 16:35:17 +0100
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-12-11 16:35:17 +0100
commita58587dc80f3406e7aa91eff46da6d19c881cf56 (patch)
tree0264a2f6a43eb33704858b4903c6751a8b1d13ae
parent17644e584e47ca2cbc83874805b930d5c4275407 (diff)
views: improve request error reporting
Add specific error messages for each http status code in the function ogserver_error(). Pass the request object to obtain the status code. Standarize the error handling code for every get(), delete() and post() as: r = server.get('/scopes') if not r: return ogserver_down('scopes') if r.status_code != requests.codes.ok: return ogserver_error(r, 'scopes')
-rw-r--r--ogcp/og_server.py18
-rw-r--r--ogcp/views.py271
2 files changed, 149 insertions, 140 deletions
diff --git a/ogcp/og_server.py b/ogcp/og_server.py
index 07ee682..872798e 100644
--- a/ogcp/og_server.py
+++ b/ogcp/og_server.py
@@ -32,15 +32,21 @@ class OGServer:
return r
def post(self, path, payload):
- r = requests.post(f'{self.URL}{path}',
- headers=self.HEADERS,
- json=payload)
+ try:
+ r = requests.post(f'{self.URL}{path}',
+ headers=self.HEADERS,
+ json=payload)
+ except requests.exceptions.ConnectionError:
+ return None
return r
def delete(self, path, payload):
- r = requests.delete(f'{self.URL}{path}',
- headers=self.HEADERS,
- json=payload)
+ try:
+ r = requests.delete(f'{self.URL}{path}',
+ headers=self.HEADERS,
+ json=payload)
+ except requests.exceptions.ConnectionError:
+ return None
return r
@property
diff --git a/ogcp/views.py b/ogcp/views.py
index e449463..6e9752b 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -6,7 +6,7 @@
# (at your option) any later version.
from flask import (
- g, render_template, url_for, flash, redirect, request, jsonify, make_response
+ g, render_template, url_for, flash, redirect, request, jsonify
)
from ogcp.forms.action_forms import (
WOLForm, SetupForm, ClientDetailsForm, ImageDetailsForm, HardwareForm,
@@ -134,8 +134,25 @@ def ogserver_down(view):
flash(_('Cannot talk to ogserver. Is ogserver down?'), category='error')
return redirect(url_for(view))
-def ogserver_error(view):
- flash(_('ogserver replied with a bad HTTP status code'), category='error')
+def ogserver_error(res, view):
+ if res.status_code == 400:
+ err_msg = _('Error 400: invalid payload')
+ elif res.status_code == 404:
+ err_msg = _('Error 404: object not found')
+ elif res.status_code == 405:
+ err_msg = _('Error 405: method not allowed')
+ elif res.status_code == 409:
+ err_msg = _('Error 409: object already exists')
+ elif res.status_code == 423:
+ err_msg = _('Error 423: object in use')
+ elif res.status_code == 501:
+ err_msg = _('Error 501: cannot connect to database')
+ elif res.status_code == 507:
+ err_msg = _('Error 500: disk full')
+ else:
+ err_msg = _(f'Received status code {res.status_code}')
+
+ flash(err_msg, category='error')
return redirect(url_for(view))
def validate_elements(elements, min_len=1, max_len=float('inf')):
@@ -661,7 +678,7 @@ def action_poweroff():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
flash(_('Client powered off successfully'), category='info')
return redirect(url_for('commands'))
@@ -756,7 +773,7 @@ def action_setup_select():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
client_name = r.json()['name']
client_choices.append((ip, f"{client_name} ({ip})"))
@@ -792,7 +809,7 @@ def action_setup_show():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
if not setup_data:
flash(_('Partition information is not available. Boot client in ogLive mode to obtain it'), category='error')
@@ -1041,7 +1058,7 @@ def action_image_restore():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
images_list = r.json()['images']
image = search_image(images_list, int(image_id))
@@ -1059,7 +1076,7 @@ def action_image_restore():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
clients_info = r.json()['clients']
@@ -1074,13 +1091,12 @@ def action_image_restore():
'type': form.method.data,
'profile': str(image['software_id']),
'id': str(image['id'])}
- server.post('/image/restore', payload)
+ r = 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:
- flash(_(f'There was a problem sending the image restore command'), category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_(f'Image restore command sent sucessfully'), category='info')
return redirect(url_for('commands'))
else:
params = request.args.to_dict()
@@ -1097,7 +1113,7 @@ def action_image_restore():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
if repo_id is None:
flash(_(f'Computers have different repos assigned'), category='error')
@@ -1113,7 +1129,7 @@ def action_image_restore():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
sort_images(images)
@@ -1129,7 +1145,7 @@ def action_image_restore():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
has_cache = False
@@ -1196,10 +1212,9 @@ def action_hardware():
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:
- flash(_(f'There was a problem sending the hardware inventory command'), category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_(f'Hardware inventory command sent sucessfully'), category='info')
return redirect(url_for('commands'))
else:
ips = parse_elements(request.args.to_dict())
@@ -1213,7 +1228,7 @@ def action_hardware():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
hardware = r.json()['hardware']
return render_template('actions/hardware.html', form=form,
@@ -1234,7 +1249,7 @@ def action_software():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
software = r.json()['software']
scopes, clients = get_scopes(set(ips))
@@ -1246,10 +1261,9 @@ def action_software():
'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:
- flash(_('Error processing software profile request: ({})').format(r.status), category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_('Software profile request sent successfully'), category='info')
else:
flash(_('Error processing software profile form'), category='error')
return redirect(url_for('commands'))
@@ -1265,7 +1279,7 @@ def action_software():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
if not r.json()['partitions']:
flash(_('Software inventory is not available. Boot client in ogLive mode to obtain it'), category='error')
@@ -1293,7 +1307,7 @@ def action_session():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
sessions = r.json()['sessions']
if not sessions:
@@ -1320,11 +1334,14 @@ def action_session():
'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))
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ if excluded_ips:
+ flash('The following clients didn\'t match the boot configuration: ' + str(excluded_ips))
return redirect(url_for('commands'))
- return make_response("400 Bad Request", 400)
+
+ flash(_(f'Boot OS command sent sucessfully'), category='info')
+ return redirect(url_for('commands'))
else:
ips = parse_elements(request.args.to_dict())
ips_list = list(ips)
@@ -1338,7 +1355,7 @@ def action_session():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
sessions = r.json()['sessions']
if not sessions:
@@ -1398,10 +1415,9 @@ def action_client_cache():
'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:
- flash(_(f'Invalid cache delete form'), category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_('Cache delete request sent successfully'), category='info')
return redirect(url_for('commands'))
else:
ips = parse_elements(request.args.to_dict())
@@ -1416,7 +1432,7 @@ def action_client_cache():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
clients_info = r.json()['clients']
@@ -1459,7 +1475,7 @@ def action_image_fetch():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
images_list = r.json()['images']
image = search_image(images_list, int(image_id))
@@ -1471,7 +1487,7 @@ def action_image_fetch():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
clients_info = r.json()['clients']
@@ -1486,10 +1502,9 @@ def action_image_fetch():
r = server.post('/cache/fetch', payload=payload)
if not r:
return ogserver_down('commands')
- if r.status_code == requests.codes.ok:
- flash(_('Cache fetch request sent successfully'), category='info')
- else:
- flash(_(f'Invalid cache fetch form'), category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_('Cache fetch request sent successfully'), category='info')
return redirect(url_for('commands'))
else:
params = request.args.to_dict()
@@ -1509,7 +1524,7 @@ def action_image_fetch():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
if repo_id is None:
flash(_(f'Computers have different repos assigned'), category='error')
@@ -1525,7 +1540,7 @@ def action_image_fetch():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
sort_images(images)
@@ -1553,7 +1568,7 @@ def action_client_info():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
db_client = r.json()
@@ -1576,7 +1591,7 @@ def action_client_info():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
form.repo.choices = [(repo["id"], repo["name"]) for repo in repositories
if db_client['repo_id'] == repo["id"]]
form.repo.render_kw = {'readonly': True}
@@ -1589,7 +1604,7 @@ def action_client_info():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
rooms = parse_scopes_from_tree(r.json(), 'room')
rooms = [(room['id'], room['name']) for room in rooms
@@ -1605,7 +1620,7 @@ def action_client_info():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
disk_form = SetupForm()
selected_disk = 1
@@ -1616,7 +1631,7 @@ def action_client_info():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
clients_info = r.json()['clients']
@@ -1634,7 +1649,7 @@ def action_client_info():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
efi_data = r.json()['clients'][0]
@@ -1702,7 +1717,7 @@ def action_client_update():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
db_client = r.json()
@@ -1721,7 +1736,7 @@ def action_client_update():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
available_modes = [(current_mode, current_mode)]
available_modes.extend([(mode, mode) for mode in r.json()['modes']
@@ -1733,7 +1748,7 @@ def action_client_update():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
room_id = db_client['room']
rooms = parse_scopes_from_tree(r.json(), 'room')
@@ -1747,7 +1762,7 @@ def action_client_update():
except ServerError:
return ogserver_down('scopes')
except ServerErrorCode:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.repo.choices = [(repo["id"], repo["name"]) for repo in repositories
if db_client['repo_id'] == repo["id"]]
form.repo.choices.extend([(repo["id"], repo["name"]) for repo in repositories
@@ -1759,7 +1774,7 @@ def action_client_update():
except ServerError:
return ogserver_down('scopes')
except ServerErrorCode:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
disk_form = SetupForm()
selected_disk = 1
@@ -1962,7 +1977,7 @@ def action_client_add():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
available_modes = [(mode, mode) for mode in r.json()['modes'] if mode == 'pxe']
available_modes.extend([(mode, mode) for mode in r.json()['modes'] if mode != 'pxe'])
@@ -1974,7 +1989,7 @@ def action_client_add():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
room_id = params['scope-room']
rooms = parse_scopes_from_tree(r.json(), 'room')
@@ -1988,7 +2003,7 @@ def action_client_add():
except ServerError:
return ogserver_down('scopes')
except ServerErrorCode:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.repo.choices = [(repo["id"], repo["name"]) for repo in repositories]
if params.get('folder'):
@@ -2081,7 +2096,7 @@ def action_clients_import_get():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
rooms = parse_scopes_from_tree(r.json(), 'room')
selected_room_id = params['scope-room']
@@ -2094,7 +2109,7 @@ def action_clients_import_get():
except ServerError:
return ogserver_down('scopes')
except ServerErrorCode:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.repo.choices = [(repo["id"], repo["name"]) for repo in repositories]
form.client_conf.render_kw = {'placeholder': PLACEHOLDER_CLIENT_IMPORT_TEXT}
@@ -2241,7 +2256,7 @@ def action_run_cmd():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
flash(_('Command sent successfully'), category='info')
return redirect(url_for('commands'))
@@ -2280,7 +2295,7 @@ def action_run_script():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
flash(_('Script run sent successfully'), category='info')
return redirect(url_for('commands'))
@@ -2298,7 +2313,7 @@ def action_run_script():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
partitions = r.json()['partitions'][1:]
if not reference_patitioning:
@@ -2313,7 +2328,7 @@ def action_run_script():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
scripts = r.json()['scripts']
@@ -2340,7 +2355,7 @@ def action_script_display_output():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
client_data = r.json()['clients']
@@ -2397,10 +2412,9 @@ def action_mode():
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:
- flash(_('Ogserver replied with status code not ok'), category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_('Client set boot mode request sent successfully'), category='info')
return redirect(url_for('commands'))
else:
@@ -2415,12 +2429,12 @@ def action_mode():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
r = server.get('/mode')
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
mode_descriptions = {
'pxe': 'ogLive (pxe)',
@@ -2483,12 +2497,9 @@ def action_oglive():
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')
- else:
- flash(_('Ogserver replied with status code not ok'),
- category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_('Client set ogLive request sent successfully'), category='info')
return redirect(url_for('commands'))
else:
@@ -2504,13 +2515,13 @@ def action_oglive():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
r = server.get('/oglive/list')
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
oglive_list = r.json()['oglive']
most_used_live = max(oglives_set, key=lambda l: len(oglives_set[l]))
@@ -2570,12 +2581,9 @@ def action_repo_set():
r = server.post('/client/repo', payload)
if not r:
return ogserver_down('commands')
- if r.status_code == requests.codes.ok:
- flash(_('Repo set ogLive request sent successfully'),
- category='info')
- else:
- flash(_('Ogserver replied with status code not ok'),
- category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_('Repo set ogLive request sent successfully'), category='info')
return redirect(url_for('commands'))
else:
@@ -2591,7 +2599,7 @@ def action_repo_set():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
form.repo.choices = [(repo["id"], repo["name"]) for repo in repositories]
@@ -2612,7 +2620,7 @@ def action_image_create():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
image_name = remove_accents(form.name.data.strip())
if ' ' in image_name:
@@ -2633,9 +2641,9 @@ def action_image_create():
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)
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ return redirect(url_for('commands'))
else:
ips = parse_elements(request.args.to_dict())
form.ip.data = " ".join(ips)
@@ -2647,7 +2655,7 @@ def action_image_create():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
invalid_part_types = get_invalid_image_partition_types()
@@ -2670,7 +2678,7 @@ def action_image_create():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
client_repo_id = r.json()['repo_id']
try:
@@ -2678,7 +2686,7 @@ def action_image_create():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
form.repository.choices = [ (repo['id'], repo['name']) for repo in repositories
if client_repo_id == repo['id']]
form.repository.render_kw = {'readonly': True}
@@ -2704,7 +2712,7 @@ def action_image_update():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
images_list = r.json()['images']
image = search_image(images_list, int(image_id))
@@ -2716,7 +2724,7 @@ def action_image_update():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
payload = {'clients': [ip],
'disk': disk,
'partition': partition,
@@ -2731,11 +2739,9 @@ def action_image_update():
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:
- flash(_('There was a problem sending the image update command'),
- category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'commands')
+ flash(_('Image update command sent sucessfully'), category='info')
return redirect(url_for('commands'))
params = request.args.to_dict()
@@ -2750,7 +2756,7 @@ def action_image_update():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
repo_id = r.json()['repo_id']
try:
@@ -2764,7 +2770,7 @@ def action_image_update():
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
sort_images(images)
@@ -2775,7 +2781,7 @@ def action_image_update():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
invalid_part_types = get_invalid_image_partition_types()
@@ -2933,7 +2939,7 @@ def action_center_update():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.comment.data = r.json()['comment']
form.name.data = r.json()['name']
@@ -2970,7 +2976,7 @@ def action_center_info():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.comment.data = r.json()['comment']
form.comment.render_kw = {'readonly': True}
@@ -3040,7 +3046,7 @@ def action_center_delete():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.center.data = params['scope-center']
form.server.data = params['scope-server']
@@ -3078,7 +3084,7 @@ def action_room_add():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
selected_center_id = params['scope-center']
centers = parse_scopes_from_tree(r.json(), 'center')
@@ -3132,7 +3138,7 @@ def action_room_update():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.name.data = r.json()['name']
form.gateway.data = r.json()['gateway']
form.netmask.data = r.json()['netmask']
@@ -3161,7 +3167,7 @@ def action_room_info():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.name.data = r.json()['name']
form.name.render_kw = {'readonly': True}
form.gateway.data = r.json()['gateway']
@@ -3201,7 +3207,7 @@ def action_room_delete():
if not r:
return ogserver_down('scopes')
if r.status_code != requests.codes.ok:
- return ogserver_error('scopes')
+ return ogserver_error(r, 'scopes')
form.room.data = params['scope-room']
form.room.render_kw = {'readonly': True}
@@ -3380,7 +3386,7 @@ def action_repo_update():
except ServerError:
return ogserver_down('manage_repos')
except ServerErrorCode:
- return ogserver_error('manage_repos')
+ return ogserver_error(r, 'manage_repos')
form.server.data = server_ip_port
form.repo_id.data = repo_id
@@ -3431,7 +3437,7 @@ def action_repo_delete():
except ServerError:
return ogserver_down('manage_repos')
except ServerErrorCode:
- return ogserver_error('manage_repos')
+ return ogserver_error(r, 'manage_repos')
form.server.data = server_ip_port
form.repo_id.data = repo_id
form.name.data = repository['name']
@@ -3470,7 +3476,7 @@ def action_repo_info():
except ServerError:
return ogserver_down('manage_repos')
except ServerErrorCode:
- return ogserver_error('manage_repos')
+ return ogserver_error(r, 'manage_repos')
form.name.data = repository['name']
form.name.render_kw = {'readonly': True}
for addr in repository['addr']:
@@ -3501,7 +3507,7 @@ def server_update_get():
if not r:
return ogserver_down('manage_servers')
if r.status_code != requests.codes.ok:
- return ogserver_error('manage_servers')
+ return ogserver_error(r, 'manage_servers')
form = ServerConfigurationForm()
server_config = r.json()['servers']
@@ -3538,7 +3544,7 @@ def server_update_post():
if not r:
return ogserver_down('manage_servers')
if r.status_code != requests.codes.ok:
- return ogserver_error('manage_servers')
+ return ogserver_error(r, 'manage_servers')
server_config = r.json()['servers']
# Remove
@@ -3551,7 +3557,7 @@ def server_update_post():
if not rd:
return ogserver_down('manage_servers')
if rd.status_code != requests.codes.ok:
- return ogserver_error('manage_servers')
+ return ogserver_error(r, 'manage_servers')
# Add
for ip in addr_list:
@@ -3569,7 +3575,7 @@ def server_update_post():
if not ra:
return ogserver_down('manage_servers')
if ra.status_code != requests.codes.ok:
- return ogserver_error('manage_servers')
+ return ogserver_error(r, 'manage_servers')
flash(_('Server update request sent successfully'), category='info')
return redirect(url_for('manage_servers'))
@@ -3660,12 +3666,9 @@ def action_live_default():
r = server.post('/oglive/default', payload)
if not r:
return ogserver_down('manage_lives')
- if r.status_code == requests.codes.ok:
- flash(_('Set default ogLive request sent successfully'),
- category='info')
- else:
- flash(_('Ogserver replied with status code not ok'),
- category='error')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error(r, 'manage_lives')
+ flash(_('Set default ogLive request sent successfully'), category='info')
return redirect(url_for('manage_lives'))
else:
params = request.args.to_dict()
@@ -3678,7 +3681,7 @@ def action_live_default():
if not r:
return ogserver_down('commands')
if r.status_code != requests.codes.ok:
- return ogserver_error('commands')
+ return ogserver_error(r, 'commands')
oglive_list = r.json()['oglive']
@@ -4025,7 +4028,7 @@ def action_image_list():
except ServerError:
return ogserver_down('images')
except ServerErrorCode:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
return render_template('actions/list_images.html',
servers=servers, responses=responses)
@@ -4063,7 +4066,7 @@ def action_image_info():
if not r:
return ogserver_down('images')
if r.status_code != requests.codes.ok:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
images = r.json()['images']
image = next(img for img in images if img['id'] == int(id))
@@ -4088,7 +4091,7 @@ def action_image_info():
except ServerError:
return ogserver_down('images')
except ServerErrorCode:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
r = server.get('/image/restrict', {'image': image['id']})
if not r:
@@ -4119,7 +4122,7 @@ def action_image_delete():
if not r:
return ogserver_down('images')
if r.status_code != requests.codes.ok:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
flash(_('Image deletion request sent successfully'), category='info')
return redirect(url_for('images'))
@@ -4137,7 +4140,7 @@ def action_image_delete():
except ServerError:
return ogserver_down('images')
except ServerErrorCode:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
form.ids.data = ' '.join(image_ids)
form.server.data = params['image-server']
@@ -4162,7 +4165,7 @@ def action_image_config():
if not r:
return ogserver_down('images')
if r.status_code != requests.codes.ok:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
flash(_('Image updated successfully'), category='info')
return redirect(url_for('images'))
@@ -4184,7 +4187,7 @@ def action_image_config():
if not r:
return ogserver_down('images')
if r.status_code != requests.codes.ok:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
form.server.data = params['image-server']
form.scopes.choices = get_available_centers()
@@ -4195,7 +4198,7 @@ def action_image_config():
except ServerError:
return ogserver_down('images')
except ServerErrorCode:
- return ogserver_error('images')
+ return ogserver_error(r, 'images')
return render_template('actions/image_config.html', form=form,
responses=responses)