summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-08-22 17:02:13 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-08-31 15:57:52 +0200
commit3dea9115b14f2a541207369fb5a72b263c94aed1 (patch)
treeca255588155a0786c3cf3f314f48e587bbde200b
parent0466b009ae6f99d62505702ba0a7ab0cf2e6eb53 (diff)
Adapt Import Clients to work with several ogServers
This commit makes Import Clients view to use ogServer field from scopesForm to send the command to the correct ogServer.
-rw-r--r--ogcp/forms/action_forms.py1
-rw-r--r--ogcp/views.py7
2 files changed, 6 insertions, 2 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index c81b326..40efd49 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -121,6 +121,7 @@ class ClientDetailsForm(FlaskForm):
create = SubmitField(label=_l('Create'))
class ImportClientsForm(FlaskForm):
+ server = HiddenField()
room = SelectField(label=_l('Room'))
dhcpd_conf = TextAreaField(label=_l('dhcpd configuration'))
import_btn = SubmitField(label=_l('Import'))
diff --git a/ogcp/views.py b/ogcp/views.py
index 560ff5c..af1df47 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -893,7 +893,9 @@ def action_clients_import_get():
return redirect(url_for('scopes'))
form = ImportClientsForm()
- r = g.server.get('/scopes')
+ form.server.data = params['scope-server']
+ server = get_server_from_ip_port(params['scope-server'])
+ r = server.get('/scopes')
rooms = parse_scopes_from_tree(r.json(), 'room')
selected_room_id = params['scope-room']
selected_room = [(room['id'], room['name'] + " (" + room['parent'] + ")")
@@ -926,6 +928,7 @@ OG_CLIENT_DEFAULT_REMOTE = False
@login_required
def action_clients_import_post():
form = ImportClientsForm(request.form)
+ server = get_server_from_ip_port(form.server.data)
clients = re.findall(OG_REGEX_DHCPD_CONF, form.dhcpd_conf.data)
if not clients:
flash(_('No clients found. Check the dhcpd.conf file.'),
@@ -943,7 +946,7 @@ def action_clients_import_post():
payload['name'] = client[0]
payload['mac'] = client[1].replace(':', '')
payload['ip'] = client[2]
- resp = g.server.post('/client/add', payload)
+ resp = server.post('/client/add', payload)
if resp.status_code != requests.codes.ok:
flash(_('ogServer: error adding client {}').format(client[0]),
category='error')