diff --git a/app/network/views.py b/app/network/views.py index c6e5869661a8f8c826aa0b796faa92287145d8d3..192998d3d9521eb04204d2a5091522b5220ade05 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}")