diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-09-28 15:02:16 +0200 |
---|---|---|
committer | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-09-28 15:02:16 +0200 |
commit | 664d032884dcd6366ca1068aa2c2f35fffc2a285 (patch) | |
tree | e2c1b333f550a616a08dbe892cf00a60bd190287 /ogcp | |
parent | ea5b22c35e170deff7321abaca5d81cb289c69f7 (diff) |
Add client details action
This action is used to visualize the specific details of a client, such
as its IP, Name, MAC, etc.
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/forms/action_forms.py | 25 | ||||
-rw-r--r-- | ogcp/templates/scopes.html | 2 | ||||
-rw-r--r-- | ogcp/views.py | 45 |
3 files changed, 70 insertions, 2 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 6479b48..ac761f5 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -1,5 +1,6 @@ from wtforms import ( - Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField + Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField, + StringField ) from flask_wtf import FlaskForm from flask_babel import _ @@ -27,3 +28,25 @@ class PartitionForm(FlaskForm): format_partition = BooleanField(label=_('Format')) modify = SubmitField(label=_('Modify')) delete = SubmitField(label=_('Delete')) + +class ClientDetailsForm(FlaskForm): + name = StringField(label=_('Name')) + ip = StringField(label=_('IP')) + mac = StringField(label=_('MAC')) + serial_number = StringField(label=_('Serial Number')) + netmask = StringField(label=_('Netmask')) + livedir = SelectField(label=_('ogLive'), + choices=[('ogLive', 'Default'),]) + remote = BooleanField(label=_('Remote')) + maintenance = BooleanField(label=_('Maintenance')) + netiface = SelectField(label=_('Interface'), + choices=[('eth0', 'eth0'), + ('eth1', 'eth1'), + ('eth2', 'eth2')]) + netdriver = SelectField(label=_('Driver'), + choices=[('generic', 'generic')]) + repo = SelectField(label=_('Repository'), + choices=[(1, 'Default')]) + room = SelectField(label=_('Room')) + boot = SelectField(label=_('Boot Mode')) + create = SubmitField(label=_('Create')) diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html index 376df67..18775b2 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="{{ _('Setup') }}" formaction="{{ url_for('action_setup_show') }}" formmethod="get"> + <input class="dropdown-item" type="submit" value="{{ _('Details') }}" + formaction="{{ url_for('action_client_info') }}" formmethod="get"> </div> </div> </form> diff --git a/ogcp/views.py b/ogcp/views.py index 8c14675..3a03078 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1,5 +1,5 @@ from flask import g, render_template, url_for, request, jsonify, make_response -from ogcp.forms.action_forms import WOLForm, PartitionForm +from ogcp.forms.action_forms import WOLForm, PartitionForm, ClientDetailsForm from ogcp.og_server import OGServer from flask_babel import _ from ogcp import app @@ -37,6 +37,15 @@ def get_client_setup(ip): partition['filesystem'] = FS_CODES[partition['filesystem']] return db_partitions +def parse_scopes_from_tree(tree, scope_type): + scopes = [] + for scope in tree['scope']: + if scope['type'] == scope_type: + scopes.append(scope) + else: + scopes += parse_scopes_from_tree(scope, scope_type) + return scopes + @app.before_request def load_config(): g.server = OGServer() @@ -186,6 +195,40 @@ def action_setup_delete(): return make_response("200 OK", 200) return make_response("400 Bad Request", 400) +@app.route('/action/client/info', methods=['GET']) +def action_client_info(): + form = ClientDetailsForm() + ips = parse_ips(request.args.to_dict()) + payload = {'client': list(ips)} + r = g.server.get('/client/info', payload) + db_client = r.json() + + form.name.data = db_client['name'] + form.ip.data = db_client['ip'] + form.mac.data = db_client['mac'] + form.serial_number.data = db_client['serial_number'] + form.netmask.data = db_client['netmask'] + form.livedir.data = db_client['livedir'] + form.remote.data = db_client['remote'] + form.maintenance.data = db_client['maintenance'] + form.netiface.data = db_client['netiface'] + form.netdriver.data = db_client['netdriver'] + form.repo.data = db_client['repo_id'] + form.room.data = db_client['room'] + form.boot.data = db_client['boot'] + + r = g.server.get('/mode') + available_modes = [(mode, mode) for mode in r.json()['modes']] + form.boot.choices = list(available_modes) + + r = g.server.get('/scopes') + rooms = parse_scopes_from_tree(r.json(), 'room') + rooms = [(room['id'], room['name']) for room in rooms] + form.room.choices = list(rooms) + + form.create.render_kw = {"style": "visibility:hidden;"} + return render_template('actions/client_details.html', form=form) + @app.route('/action/reboot', methods=['POST']) def action_reboot(): ips = parse_ips(request.form.to_dict()) |