summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-09-28 15:04:00 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-09-28 15:04:00 +0200
commit93ffa115fe9dc5efb928232f797fbcacdec494b1 (patch)
tree16673e75ac1955c43e8d86a024beeedf9b511e9a /ogcp/views.py
parent664d032884dcd6366ca1068aa2c2f35fffc2a285 (diff)
Add create client action
This action provides the functionality to add a new client to an ogServer.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 3a03078..268eea4 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -229,6 +229,41 @@ def action_client_info():
form.create.render_kw = {"style": "visibility:hidden;"}
return render_template('actions/client_details.html', form=form)
+@app.route('/action/client/add', methods=['GET', 'POST'])
+def action_client_add():
+ form = ClientDetailsForm(request.form)
+ if request.method == 'POST':
+ payload = {"boot": form.boot.data,
+ "ip": form.ip.data,
+ "livedir": form.livedir.data,
+ "mac": form.mac.data,
+ "maintenance": form.maintenance.data,
+ "name": form.name.data,
+ "netdriver": form.netdriver.data,
+ "netiface": form.netiface.data,
+ "netmask": form.netmask.data,
+ "remote": form.remote.data,
+ "repo_id": int(form.repo.data),
+ "room": int(form.room.data),
+ "serial_number": form.serial_number.data}
+
+ r = g.server.post('/client/add', payload)
+ if r.status_code == requests.codes.ok:
+ return make_response("200 OK", 200)
+ return make_response("400 Bad Request", 400)
+ else:
+ 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 = {"formaction": url_for('action_client_add')}
+ 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())