From 0d575840d08ffdfc9af406bc617ebbfb24272d2e Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Wed, 23 Jan 2019 11:53:31 +0100 Subject: [PATCH] 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 --- app/network/forms.py | 2 ++ app/network/views.py | 6 +++++- app/settings.py | 2 ++ app/templates/network/view_host.html | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/network/forms.py b/app/network/forms.py index b91962a..cd89d47 100644 --- a/app/network/forms.py +++ b/app/network/forms.py @@ -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): diff --git a/app/network/views.py b/app/network/views.py index 2835a05..2a539d8 100644 --- a/app/network/views.py +++ b/app/network/views.py @@ -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) diff --git a/app/settings.py b/app/settings.py index b4ac8f7..f7fd211 100644 --- a/app/settings.py +++ b/app/settings.py @@ -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]) diff --git a/app/templates/network/view_host.html b/app/templates/network/view_host.html index 4f16c2e..544ab6e 100644 --- a/app/templates/network/view_host.html +++ b/app/templates/network/view_host.html @@ -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> -- GitLab