Просмотр исходного кода

Closes #5975: Allow partial vCPU allocations for virtual machines

Jeremy Stretch 4 лет назад
Родитель
Сommit
2bb4a81e23

+ 3 - 1
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.

+ 3 - 0
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

+ 17 - 0
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)]),
+        ),
+    ]

+ 8 - 2
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,