diff --git a/app/network/forms.py b/app/network/forms.py index 644d83b964368e7a6c5c475115fc822ab0af1359..deb988edfcae2c8a18b36a0eef3ee8263529977a 100644 --- a/app/network/forms.py +++ b/app/network/forms.py @@ -225,6 +225,7 @@ 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) + osversion = SelectField("OS Version") skip_post_install_job = BooleanField("Skip post install job", default=False) def __init__(self, *args, **kwargs): @@ -232,6 +233,9 @@ class CreateVMForm(CSEntryForm): 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"]) + self.osversion.choices = utils.get_choices( + current_app.config["VM_OSVERSION_CHOICES"] + ) class GenerateZTPConfigForm(CSEntryForm): diff --git a/app/network/views.py b/app/network/views.py index 3cdc8de03dcdc6dd030c437848923eb06955f3bd..88aaffe3adb94e103cf427e596948d79e7e4ce57 100644 --- a/app/network/views.py +++ b/app/network/views.py @@ -151,15 +151,11 @@ def view_host(name): elif host.device_type.name.startswith("Virtual"): form = CreateVMForm() if host.is_ioc: - form.cores.choices = utils.get_choices( - current_app.config["VIOC_CORES_CHOICES"] - ) - form.memory.choices = utils.get_choices( - current_app.config["VIOC_MEMORY_CHOICES"] - ) - form.disk.choices = utils.get_choices( - current_app.config["VIOC_DISK_CHOICES"] - ) + for field in ("cores", "memory", "disk", "osversion"): + key = f"VIOC_{field.upper()}_CHOICES" + getattr(form, field).choices = utils.get_choices( + current_app.config[key] + ) else: form = None if form is not None and form.validate_on_submit(): @@ -186,21 +182,13 @@ 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 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) - # If we don't flag the field as modified, it's not saved to the database - # Might be because we update an existing dict - sa.orm.attributes.flag_modified(host, "ansible_vars") - except AttributeError: - host.ansible_vars = csentry_vars task = tasks.trigger_vm_creation( - host, skip_post_install_job=form.skip_post_install_job.data + host, + vm_disk_size=int(form.disk.data), + vm_cores=int(form.cores.data), + vm_memory=int(form.memory.data) * 1024, + vm_osversion=form.osversion.data, + skip_post_install_job=form.skip_post_install_job.data, ) db.session.commit() current_app.logger.info(f"Creation of {name} requested: task {task.id}") diff --git a/app/settings.py b/app/settings.py index 33222d38642697472f1759de79ed42b6a5a2bff5..094c8dd579762cd63b4bc2c11c9321407477a759 100644 --- a/app/settings.py +++ b/app/settings.py @@ -112,9 +112,11 @@ 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] +VM_OSVERSION_CHOICES = ["centos7", "windows10", "windows2016"] VIOC_CORES_CHOICES = [1, 2, 4] VIOC_MEMORY_CHOICES = [2, 4, 8] VIOC_DISK_CHOICES = [15, 50, 100, 250] +VIOC_OSVERSION_CHOICES = ["centos7"] # Sentry integration CSENTRY_RELEASE = raven.fetch_git_sha(Path(__file__).parents[1]) diff --git a/app/tasks.py b/app/tasks.py index 840636e59a7fff0e20eea5c080110c4019a8f5f4..6543c5a1a24913a8755d0352af282a141d654d65 100644 --- a/app/tasks.py +++ b/app/tasks.py @@ -81,10 +81,19 @@ class TaskWorker(Worker): super().prepare_job_execution(job) -def trigger_vm_creation(host, skip_post_install_job): +def trigger_vm_creation( + host, vm_disk_size, vm_cores, vm_memory, vm_osversion, skip_post_install_job +): """Trigger a job to create a virtual machine or virtual IOC""" domain = str(host.main_interface.network.domain) - extra_vars = [f"vmname={host.name}", f"domain={domain}"] + extra_vars = [ + f"vmname={host.name}", + f"domain={domain}", + f"vm_disk_size={vm_disk_size}", + f"vm_cores={vm_cores}", + f"vm_memory={vm_memory}", + f"vm_osversion={vm_osversion}", + ] if host.is_ioc: task_name = "trigger_vioc_creation" job_template = current_app.config["AWX_CREATE_VIOC"] diff --git a/app/templates/network/view_host.html b/app/templates/network/view_host.html index 52705debf17257c27d2c55c1b9059b08a2d7cff7..10a2208cd5646f0bf5fa4b54f441a2c3dea0e254 100644 --- a/app/templates/network/view_host.html +++ b/app/templates/network/view_host.html @@ -78,6 +78,7 @@ {{ render_field(form.cores, label_size='5', input_size='7') }} {{ render_field(form.memory, label_size='5', input_size='7') }} {{ render_field(form.disk, label_size='5', input_size='7') }} + {{ render_field(form.osversion, label_size='5', input_size='7') }} {% if current_user.is_admin %} {{ render_field(form.skip_post_install_job, label_size='5', input_size='7') }} {% endif %} diff --git a/docs/_static/create_vioc.png b/docs/_static/create_vioc.png index a0d25727887dff5098832992539ddd6bfdb5ea14..c61834d07006643732641319b7253038dd1401c1 100644 Binary files a/docs/_static/create_vioc.png and b/docs/_static/create_vioc.png differ diff --git a/docs/_static/create_vm.png b/docs/_static/create_vm.png index 9eeefdf59d035977d1396411044bb7c8c9a2889a..223ae69d59a82164627f0c2304d06fcd4e219944 100644 Binary files a/docs/_static/create_vm.png and b/docs/_static/create_vm.png differ diff --git a/docs/_static/create_vm_confirmation.png b/docs/_static/create_vm_confirmation.png index 49482bfc7ffb3cdf1c8c5518af2e075039403de5..6f5d38b3f2141721994645bfe52ce77d465d0a62 100644 Binary files a/docs/_static/create_vm_confirmation.png and b/docs/_static/create_vm_confirmation.png differ