summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2020-10-29 14:59:13 +0100
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-10-29 15:03:35 +0100
commitc08aca92196cdd8df4c8d81da71e248b407f5bb2 (patch)
treeaa61c3524b58a0b50886a92cf4fe6eca36ba822b /ogcp/views.py
parenta8d7494ab9601d2ea4fb2065018580fb2a1c95b3 (diff)
Add software action
This action lists every piece of software installed in an OS from a client. This action can handle listing the software from the DB as well as updating that DB with the latest client information.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 7aaf60d..09486d5 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1,7 +1,7 @@
from flask import g, render_template, url_for, request, jsonify, make_response
from ogcp.forms.action_forms import (
WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm,
- ImageRestoreForm, ImageCreateForm
+ ImageRestoreForm, ImageCreateForm, SoftwareForm
)
from ogcp.og_server import OGServer
from flask_babel import _
@@ -269,6 +269,44 @@ def action_hardware():
return render_template('actions/hardware.html', form=form,
hardware=hardware)
+@app.route('/action/software', methods=['GET', 'POST'])
+def action_software():
+ form = SoftwareForm(request.form)
+ if request.method == 'POST':
+ ips = form.ips.data.split(' ')
+ disk, partition = form.os.data.split(' ')
+ if form.view.data:
+ r = g.server.get('/software', payload={'client': ips,
+ 'disk': int(disk),
+ 'partition': int(partition)})
+ if r.status_code == requests.codes.ok:
+ return r.json()
+
+ elif form.update.data:
+ r = g.server.post('/software', payload={'clients': ips,
+ 'disk': disk,
+ 'partition': partition})
+ if r.status_code == requests.codes.ok:
+ return make_response(f"Se generó correctamente el perfil "
+ f"software de {ips[0]} D:{disk} "
+ f"P:{partition}",
+ 200)
+
+ return make_response("400 Bad Request", 400)
+ else:
+ ips = parse_ips(request.args.to_dict())
+ form.ips.data = ' '.join(ips)
+ r = g.server.get('/client/setup', payload={'client': list(ips)})
+
+ for part in r.json()['partitions'][1:]:
+ form.os.choices.append(
+ (f"{part.get('disk')} {part.get('partition')}",
+ f"Disco {part.get('disk')} | Partición {part.get('partition')} "
+ f"| {PART_TYPE_CODES[part.get('code')]} "
+ f"{FS_CODES[part.get('filesystem')]}")
+ )
+ return render_template('actions/software.html', form=form)
+
@app.route('/action/session', methods=['GET', 'POST'])
def action_session():
form = SessionForm(request.form)