summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py64
2 files changed, 66 insertions, 0 deletions
diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html
index d07e7d3..9b93971 100644
--- a/ogcp/templates/scopes.html
+++ b/ogcp/templates/scopes.html
@@ -23,6 +23,8 @@
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<input class="btn btn-light dropdown-item {% block nav_client_add %}{% endblock %}" type="submit" value="{{ _('Add client') }}"
form="scopesForm" formaction="{{ url_for('action_client_add') }}" formmethod="get">
+ <input class="btn btn-light dropdown-item {% block nav_client_update %}{% endblock %}" type="submit" value="{{ _('Edit client') }}"
+ form="scopesForm" formaction="{{ url_for('action_client_update') }}" formmethod="get">
<input class="btn btn-light dropdown-item {% block nav_clients_import %}{% endblock %}" type="submit" value="{{ _('Import clients') }}"
form="scopesForm" formaction="{{ url_for('action_clients_import_get') }}" formmethod="get">
<input class="btn btn-light dropdown-item {% block nav_client_delete %}{% endblock %}" type="submit" value="{{ _('Delete client') }}"
diff --git a/ogcp/views.py b/ogcp/views.py
index 18a107c..72be70a 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -854,6 +854,70 @@ def action_client_info():
return render_template('actions/client_details.html', form=form,
parent="commands.html", scopes=scopes, setup=setup)
+@app.route('/action/client/update', methods=['GET', 'POST'])
+@login_required
+def action_client_update():
+ form = ClientDetailsForm(request.form)
+ if request.method == 'POST':
+ payload = {"ip": form.ip.data,
+ "serial_number": form.serial_number.data,
+ "netdriver": "generic",
+ "maintenance": form.maintenance.data,
+ "netiface": form.netiface.data,
+ "repo_id": int(form.repo.data),
+ "netmask": form.netmask.data,
+ "remote": form.remote.data,
+ "room": int(form.room.data),
+ "name": form.name.data,
+ "mac": form.mac.data }
+ server = get_server_from_ip_port(form.server.data)
+ r = server.post('/client/update', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('ogServer: error updating client'),
+ category='error')
+ else:
+ flash(_('Client updated successfully'), category='info')
+ return redirect(url_for("scopes"))
+ else:
+ ips = parse_elements(request.args.to_dict())
+ if not validate_elements(ips, max_len=1):
+ flash(_('Please, select one client'), category='error')
+ return redirect(url_for('scopes'))
+
+ server = get_server_from_clients(list(ips))
+ scopes, clients = get_scopes()
+
+ payload = {'client': list(ips)}
+ r = server.get('/client/info', payload)
+ db_client = r.json()
+
+ form.server.data = "{0}:{1}".format(server.ip, server.port)
+ print("server ip:", form.server.data)
+ form.ip.data = db_client['ip']
+ form.ip.render_kw = {'readonly': True}
+ form.name.data = db_client['name']
+ form.mac.data = db_client['mac']
+ form.serial_number.data = db_client['serial_number']
+ form.netmask.data = db_client['netmask']
+ form.livedir.render_kw = {'readonly': True}
+ form.remote.data = db_client['remote']
+ form.maintenance.data = db_client['maintenance']
+ form.netiface.data = db_client['netiface']
+ form.repo.data = db_client['repo_id']
+ form.boot.render_kw = {'readonly': True}
+
+ r = server.get('/scopes')
+ room_id = db_client['room']
+ rooms = parse_scopes_from_tree(r.json(), 'room')
+ rooms = [(room['id'], room['name']) for room in rooms
+ if room['id'] == int(room_id)]
+ form.room.choices = list(rooms)
+ form.room.render_kw = {'readonly': True}
+
+ form.create.render_kw = {"formaction": url_for('action_client_update')}
+ return render_template('actions/client_details.html', form=form,
+ parent="scopes.html", scopes=scopes)
+
@app.route('/action/client/add', methods=['GET', 'POST'])
@login_required
def action_client_add():