summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ogcp/forms/action_forms.py6
-rw-r--r--ogcp/templates/actions/software.html11
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py40
4 files changed, 58 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index 154e9f0..bc0915a 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -33,6 +33,12 @@ class HardwareForm(FlaskForm):
ips = HiddenField()
refresh = SubmitField(label=_('Refresh'))
+class SoftwareForm(FlaskForm):
+ ips = HiddenField()
+ os = SelectField(label=_('Partition'), choices=[])
+ view = SubmitField(label=_('View'))
+ update = SubmitField(label=_('Update'))
+
class SessionForm(FlaskForm):
ips = HiddenField()
os = RadioField(label=_('Session'), choices=[])
diff --git a/ogcp/templates/actions/software.html b/ogcp/templates/actions/software.html
new file mode 100644
index 0000000..713f89b
--- /dev/null
+++ b/ogcp/templates/actions/software.html
@@ -0,0 +1,11 @@
+{% extends 'base.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% block content %}
+
+{{ wtf.quick_form(form,
+ action=url_for('action_software'),
+ method='post',
+ button_map={'view': 'primary', 'update': 'primary'}) }}
+
+{% endblock %}
diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html
index 19ce9d8..d810b2a 100644
--- a/ogcp/templates/scopes.html
+++ b/ogcp/templates/scopes.html
@@ -42,6 +42,8 @@
formaction="{{ url_for('action_refresh') }}" formmethod="post">
<input class="dropdown-item" type="submit" value="{{ _('Hardware') }}"
formaction="{{ url_for('action_hardware') }}" formmethod="get">
+ <input class="dropdown-item" type="submit" value="{{ _('Software') }}"
+ formaction="{{ url_for('action_software') }}" formmethod="get">
<input class="dropdown-item" type="submit" value="{{ _('Sessions') }}"
formaction="{{ url_for('action_session') }}" formmethod="get">
<input class="dropdown-item" type="submit" value="{{ _('Restore Image') }}"
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)