From 1814b4d021f2ae3755857240bf6562016373a87b Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Wed, 28 Nov 2018 15:36:08 +0100 Subject: [PATCH] Save VM memory and cores as ansible variables JIRA INFRA-640 --- app/network/views.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/network/views.py b/app/network/views.py index c6e5869..192998d 100644 --- a/app/network/views.py +++ b/app/network/views.py @@ -180,9 +180,24 @@ def view_host(name): flash(f"Only admin users are allowed to create a VM!", "info") return redirect(url_for("network.view_host", name=name)) else: + # Save the requested memory and cores as ansible variables + csentry_vars = { + "csentry_vm_memory": int(form.memory.data) * 1024, + "csentry_vm_cores": int(form.cores.data), + } + try: + host.ansible_vars.update(csentry_vars) + # If we don't flag the field as modified, it's not saved to the database + # Might be because we update an existing directory + sa.orm.attributes.flag_modified(host, "ansible_vars") + except AttributeError: + host.ansible_vars = csentry_vars interface = host.interfaces[0] task = tasks.trigger_vm_creation( - name, interface, int(form.memory.data) * 1000, form.cores.data + name, + interface, + csentry_vars["csentry_vm_memory"], + csentry_vars["csentry_vm_cores"], ) db.session.commit() current_app.logger.info(f"Creation of {name} requested: task {task.id}") -- GitLab