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

Pass disk size in inventory when creating VM

- Disk size added to the create VM form
- Disk size saved to proxmox_disk_space variable in host inventory

The proxmox_disk_space variable is used by the Ansible job when creating
the machine.

JIRA INFRA-759 #action In Progress
parent fb7fa292
No related branches found
No related tags found
No related merge requests found
......@@ -230,11 +230,13 @@ class HostInterfaceForm(HostForm, InterfaceForm):
class CreateVMForm(CSEntryForm):
cores = SelectField("Cores", default=2, coerce=int)
memory = SelectField("Memory (GB)", default=2, coerce=int)
disk = SelectField("Disk (GB)", default=15, coerce=int)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.cores.choices = utils.get_choices(current_app.config["VM_CORES_CHOICES"])
self.memory.choices = utils.get_choices(current_app.config["VM_MEMORY_CHOICES"])
self.disk.choices = utils.get_choices(current_app.config["VM_DISK_CHOICES"])
class GenerateZTPConfigForm(CSEntryForm):
......
......@@ -154,6 +154,9 @@ def view_host(name):
form.memory.choices = utils.get_choices(
current_app.config["VIOC_MEMORY_CHOICES"]
)
form.disk.choices = utils.get_choices(
current_app.config["VIOC_DISK_CHOICES"]
)
else:
form = None
if form is not None and form.validate_on_submit():
......@@ -180,10 +183,11 @@ 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
# Save the requested disk, memory and cores as ansible variables
csentry_vars = {
"csentry_vm_memory": int(form.memory.data) * 1024,
"csentry_vm_cores": int(form.cores.data),
"proxmox_disk_space": int(form.disk.data),
}
try:
host.ansible_vars.update(csentry_vars)
......
......@@ -100,8 +100,10 @@ AWX_VM_CREATION_ENABLED = False
VM_CORES_CHOICES = [1, 2, 4, 6, 8, 24]
VM_MEMORY_CHOICES = [2, 4, 8, 16, 32, 128]
VM_DISK_CHOICES = [15, 50, 100, 250]
VIOC_CORES_CHOICES = [1, 3, 6]
VIOC_MEMORY_CHOICES = [2, 4, 8]
VIOC_DISK_CHOICES = [15, 50, 100, 250]
# Sentry integration
CSENTRY_RELEASE = raven.fetch_git_sha(Path(__file__).parents[1])
......
......@@ -75,6 +75,7 @@
{{ form.hidden_tag() }}
{{ render_field(form.cores, label_size='6', input_size='6') }}
{{ render_field(form.memory, label_size='6', input_size='6') }}
{{ render_field(form.disk, label_size='6', input_size='6') }}
{{ submit_button_with_confirmation('Create ' + vm_type, 'Do you really want to create the ' + vm_type + ' ' + host.name + '?') }}
</form>
</div>
......
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