Skip to content
Snippets Groups Projects
Commit 1814b4d0 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Save VM memory and cores as ansible variables

JIRA INFRA-640
parent 5e1ea823
No related branches found
No related tags found
No related merge requests found
...@@ -180,9 +180,24 @@ def view_host(name): ...@@ -180,9 +180,24 @@ def view_host(name):
flash(f"Only admin users are allowed to create a VM!", "info") flash(f"Only admin users are allowed to create a VM!", "info")
return redirect(url_for("network.view_host", name=name)) return redirect(url_for("network.view_host", name=name))
else: 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] interface = host.interfaces[0]
task = tasks.trigger_vm_creation( 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() db.session.commit()
current_app.logger.info(f"Creation of {name} requested: task {task.id}") current_app.logger.info(f"Creation of {name} requested: task {task.id}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment