From 2bb4a81e2318607ee4c02525a52fdbd58042acf7 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 16 Mar 2021 11:52:59 -0400 Subject: [PATCH] Closes #5975: Allow partial vCPU allocations for virtual machines --- docs/models/virtualization/virtualmachine.md | 4 +++- docs/release-notes/version-2.11.md | 3 +++ .../0021_virtualmachine_vcpus_decimal.py | 17 +++++++++++++++++ netbox/virtualization/models.py | 10 ++++++++-- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 netbox/virtualization/migrations/0021_virtualmachine_vcpus_decimal.py diff --git a/docs/models/virtualization/virtualmachine.md b/docs/models/virtualization/virtualmachine.md index 40e9ef2c0..de9b5f214 100644 --- a/docs/models/virtualization/virtualmachine.md +++ b/docs/models/virtualization/virtualmachine.md @@ -11,4 +11,6 @@ Like devices, each VM can be assigned a platform and/or functional role, and mus * Failed * Decommissioning -Additional fields are available for annotating the vCPU count, memory (GB), and disk (GB) allocated to each VM. Each VM may optionally be assigned to a tenant. Virtual machines may have virtual interfaces assigned to them, but do not support any physical component. +Additional fields are available for annotating the vCPU count, memory (GB), and disk (GB) allocated to each VM. A VM may be allocated a partial vCPU count (e.g. 1.5 vCPU). + +Each VM may optionally be assigned to a tenant. Virtual machines may have virtual interfaces assigned to them, but do not support any physical component. diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index b99c3191e..973b00f1c 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -79,6 +79,7 @@ The ObjectChange model (which is used to record the creation, modification, and * [#5895](https://github.com/netbox-community/netbox/issues/5895) - Rename RackGroup to Location * [#5901](https://github.com/netbox-community/netbox/issues/5901) - Add `created` and `last_updated` fields to device component models * [#5972](https://github.com/netbox-community/netbox/issues/5972) - Enable bulk editing for organizational models +* [#5975](https://github.com/netbox-community/netbox/issues/5975) - Allow partial vCPU allocations for virtual machines ### Other Changes @@ -129,3 +130,5 @@ The ObjectChange model (which is used to record the creation, modification, and * ipam.VLANGroup * Added the `scope_type`, `scope_id`, and `scope` fields (`scope` is a generic foreign key) * Dropped the `site` foreign key field +* virtualization.VirtualMachine + * `vcpus` has been changed from an integer to a decimal value diff --git a/netbox/virtualization/migrations/0021_virtualmachine_vcpus_decimal.py b/netbox/virtualization/migrations/0021_virtualmachine_vcpus_decimal.py new file mode 100644 index 000000000..0d82fcb43 --- /dev/null +++ b/netbox/virtualization/migrations/0021_virtualmachine_vcpus_decimal.py @@ -0,0 +1,17 @@ +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('virtualization', '0020_standardize_models'), + ] + + operations = [ + migrations.AlterField( + model_name='virtualmachine', + name='vcpus', + field=models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True, validators=[django.core.validators.MinValueValidator(0.01)]), + ), + ] diff --git a/netbox/virtualization/models.py b/netbox/virtualization/models.py index 32aface36..f904b6756 100644 --- a/netbox/virtualization/models.py +++ b/netbox/virtualization/models.py @@ -1,6 +1,7 @@ from django.conf import settings from django.contrib.contenttypes.fields import GenericRelation from django.core.exceptions import ValidationError +from django.core.validators import MinValueValidator from django.db import models from django.urls import reverse @@ -255,10 +256,15 @@ class VirtualMachine(PrimaryModel, ConfigContextModel): null=True, verbose_name='Primary IPv6' ) - vcpus = models.PositiveSmallIntegerField( + vcpus = models.DecimalField( + max_digits=6, + decimal_places=2, blank=True, null=True, - verbose_name='vCPUs' + verbose_name='vCPUs', + validators=( + MinValueValidator(0.01), + ) ) memory = models.PositiveIntegerField( blank=True,