diff options
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 64 |
1 files changed, 64 insertions, 0 deletions
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(): |