summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2023-11-24 10:49:01 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2023-11-24 11:04:30 +0100
commit3f27dd3ef140248fb790a7c616335525a87e31fd (patch)
treeb00d87d8c657e889818a13fcb443aab53fbd04a4 /ogcp/views.py
parent3a0cdbda5a7f711d23ef4680f553800780f8f7ae (diff)
views: allow to edit a client
Add a form to allow the user to update a client. ip field is in read only mode because this is the primary key to identify a client in db. Fields corresponding to boot mode (ie. oglivedir and boot) are also in read only for now; ogServer has to fix set boot mode functionality before it can be added here.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py64
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():