mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-13 20:49:52 +02:00
Merge branch 'main' into feature
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from dcim.choices import InterfaceModeChoices
|
||||
@@ -13,6 +14,7 @@ from tenancy.models import Tenant
|
||||
from utilities.forms import BulkRenameForm, add_blank_choice
|
||||
from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.utils import get_capacity_unit_label
|
||||
from utilities.forms.widgets import BulkEditNullBooleanSelect
|
||||
|
||||
from ..choices import *
|
||||
@@ -171,11 +173,11 @@ class VirtualMachineBulkEditForm(PrimaryModelBulkEditForm):
|
||||
)
|
||||
memory = forms.IntegerField(
|
||||
required=False,
|
||||
label=_('Memory (MB)')
|
||||
label=_('Memory')
|
||||
)
|
||||
disk = forms.IntegerField(
|
||||
required=False,
|
||||
label=_('Disk (MB)')
|
||||
label=_('Disk')
|
||||
)
|
||||
config_template = DynamicModelChoiceField(
|
||||
queryset=ConfigTemplate.objects.all(),
|
||||
@@ -194,6 +196,13 @@ class VirtualMachineBulkEditForm(PrimaryModelBulkEditForm):
|
||||
'description', 'comments',
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit labels based on configured RAM_BASE_UNIT / DISK_BASE_UNIT (MB vs MiB)
|
||||
self.fields['memory'].label = _('Memory ({unit})').format(unit=get_capacity_unit_label(settings.RAM_BASE_UNIT))
|
||||
self.fields['disk'].label = _('Disk ({unit})').format(unit=get_capacity_unit_label(settings.DISK_BASE_UNIT))
|
||||
|
||||
|
||||
class VMInterfaceBulkEditForm(OwnerMixin, NetBoxModelBulkEditForm):
|
||||
virtual_machine = forms.ModelChoiceField(
|
||||
@@ -347,7 +356,7 @@ class VirtualDiskBulkEditForm(OwnerMixin, NetBoxModelBulkEditForm):
|
||||
)
|
||||
size = forms.IntegerField(
|
||||
required=False,
|
||||
label=_('Size (MB)')
|
||||
label=_('Size')
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
@@ -361,6 +370,12 @@ class VirtualDiskBulkEditForm(OwnerMixin, NetBoxModelBulkEditForm):
|
||||
)
|
||||
nullable_fields = ('description',)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit label based on configured DISK_BASE_UNIT (MB vs MiB)
|
||||
self.fields['size'].label = _('Size ({unit})').format(unit=get_capacity_unit_label(settings.DISK_BASE_UNIT))
|
||||
|
||||
|
||||
class VirtualDiskBulkRenameForm(BulkRenameForm):
|
||||
pk = forms.ModelMultipleChoiceField(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from dcim.choices import *
|
||||
@@ -12,6 +13,7 @@ from tenancy.forms import ContactModelFilterForm, TenancyFilterForm
|
||||
from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES
|
||||
from utilities.forms.fields import DynamicModelMultipleChoiceField, TagFilterField
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.utils import get_capacity_unit_label
|
||||
from vpn.models import L2VPN
|
||||
|
||||
from ..choices import *
|
||||
@@ -327,8 +329,14 @@ class VirtualDiskFilterForm(OwnerFilterMixin, NetBoxModelFilterSetForm):
|
||||
label=_('Virtual machine')
|
||||
)
|
||||
size = forms.IntegerField(
|
||||
label=_('Size (MB)'),
|
||||
label=_('Size'),
|
||||
required=False,
|
||||
min_value=1
|
||||
)
|
||||
tag = TagFilterField(model)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit label based on configured DISK_BASE_UNIT (MB vs MiB)
|
||||
self.fields['size'].label = _('Size ({unit})').format(unit=get_capacity_unit_label(settings.DISK_BASE_UNIT))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from django import forms
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@@ -16,6 +17,7 @@ from tenancy.forms import TenancyForm
|
||||
from utilities.forms import ConfirmationForm, get_field_value
|
||||
from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField, JSONField, SlugField
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.utils import get_capacity_unit_label
|
||||
from utilities.forms.widgets import HTMXSelect
|
||||
|
||||
from ..models import *
|
||||
@@ -278,6 +280,10 @@ class VirtualMachineForm(TenancyForm, PrimaryModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit labels based on configured RAM_BASE_UNIT / DISK_BASE_UNIT (MB vs MiB)
|
||||
self.fields['memory'].label = _('Memory ({unit})').format(unit=get_capacity_unit_label(settings.RAM_BASE_UNIT))
|
||||
self.fields['disk'].label = _('Disk ({unit})').format(unit=get_capacity_unit_label(settings.DISK_BASE_UNIT))
|
||||
|
||||
# Populate virtual machine type defaults, if any
|
||||
self._populate_virtual_machine_type_defaults()
|
||||
|
||||
@@ -476,3 +482,9 @@ class VirtualDiskForm(VMComponentForm):
|
||||
fields = [
|
||||
'virtual_machine', 'name', 'size', 'description', 'owner', 'tags',
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit label based on configured DISK_BASE_UNIT (MB vs MiB)
|
||||
self.fields['size'].label = _('Size ({unit})').format(unit=get_capacity_unit_label(settings.DISK_BASE_UNIT))
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('dcim', '0228_cable_bundle'),
|
||||
('dcim', '0229_cable_bundle'),
|
||||
('extras', '0135_configtemplate_debug'),
|
||||
('ipam', '0088_rename_vlangroup_total_vlan_ids'),
|
||||
('tenancy', '0023_add_mptt_tree_indexes'),
|
||||
|
||||
@@ -3,7 +3,7 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('dcim', '0231_default_ordering_indexes'),
|
||||
('dcim', '0232_default_ordering_indexes'),
|
||||
('extras', '0137_default_ordering_indexes'),
|
||||
('ipam', '0089_default_ordering_indexes'),
|
||||
('tenancy', '0024_default_ordering_indexes'),
|
||||
|
||||
@@ -214,12 +214,12 @@ class VirtualMachine(
|
||||
memory = models.PositiveIntegerField(
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_('memory (MB)')
|
||||
verbose_name=_('memory')
|
||||
)
|
||||
disk = models.PositiveIntegerField(
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_('disk (MB)')
|
||||
verbose_name=_('disk')
|
||||
)
|
||||
serial = models.CharField(
|
||||
verbose_name=_('serial number'),
|
||||
@@ -568,7 +568,7 @@ class VMInterface(ComponentModel, BaseInterface, TrackingModelMixin):
|
||||
|
||||
class VirtualDisk(ComponentModel, TrackingModelMixin):
|
||||
size = models.PositiveIntegerField(
|
||||
verbose_name=_('size (MB)'),
|
||||
verbose_name=_('size'),
|
||||
)
|
||||
|
||||
class Meta(ComponentModel.Meta):
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from dcim.tables.devices import BaseInterfaceTable
|
||||
from netbox.tables import NetBoxTable, PrimaryModelTable, columns
|
||||
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
|
||||
from utilities.templatetags.helpers import humanize_disk_megabytes
|
||||
from utilities.templatetags.helpers import humanize_disk_capacity, humanize_ram_capacity
|
||||
|
||||
from ..models import VirtualDisk, VirtualMachine, VirtualMachineType, VMInterface
|
||||
from .template_code import *
|
||||
@@ -130,8 +130,11 @@ class VirtualMachineTable(TenancyColumnsMixin, ContactsColumnMixin, PrimaryModel
|
||||
'vcpus', 'memory', 'disk', 'primary_ip',
|
||||
)
|
||||
|
||||
def render_memory(self, value):
|
||||
return humanize_ram_capacity(value)
|
||||
|
||||
def render_disk(self, value):
|
||||
return humanize_disk_megabytes(value)
|
||||
return humanize_disk_capacity(value)
|
||||
|
||||
|
||||
#
|
||||
@@ -221,7 +224,7 @@ class VirtualDiskTable(NetBoxTable):
|
||||
}
|
||||
|
||||
def render_size(self, value):
|
||||
return humanize_disk_megabytes(value)
|
||||
return humanize_disk_capacity(value)
|
||||
|
||||
|
||||
class VirtualMachineVirtualDiskTable(VirtualDiskTable):
|
||||
|
||||
26
netbox/virtualization/tests/test_tables.py
Normal file
26
netbox/virtualization/tests/test_tables.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from utilities.testing import TableTestCases
|
||||
from virtualization.tables import *
|
||||
|
||||
|
||||
class ClusterTypeTableTest(TableTestCases.StandardTableTestCase):
|
||||
table = ClusterTypeTable
|
||||
|
||||
|
||||
class ClusterGroupTableTest(TableTestCases.StandardTableTestCase):
|
||||
table = ClusterGroupTable
|
||||
|
||||
|
||||
class ClusterTableTest(TableTestCases.StandardTableTestCase):
|
||||
table = ClusterTable
|
||||
|
||||
|
||||
class VirtualMachineTableTest(TableTestCases.StandardTableTestCase):
|
||||
table = VirtualMachineTable
|
||||
|
||||
|
||||
class VMInterfaceTableTest(TableTestCases.StandardTableTestCase):
|
||||
table = VMInterfaceTable
|
||||
|
||||
|
||||
class VirtualDiskTableTest(TableTestCases.StandardTableTestCase):
|
||||
table = VirtualDiskTable
|
||||
@@ -40,7 +40,7 @@ class VirtualMachinePanel(panels.ObjectAttributesPanel):
|
||||
virtual_machine_type = attrs.RelatedObjectAttr('virtual_machine_type', linkify=True, label=_('Type'))
|
||||
status = attrs.ChoiceAttr('status')
|
||||
start_on_boot = attrs.ChoiceAttr('start_on_boot')
|
||||
role = attrs.RelatedObjectAttr('role', linkify=True)
|
||||
role = attrs.RelatedObjectAttr('role', linkify=True, colored=True)
|
||||
platform = attrs.NestedObjectAttr('platform', linkify=True, max_depth=3)
|
||||
description = attrs.TextAttr('description')
|
||||
serial = attrs.TextAttr('serial', label=_('Serial number'), style='font-monospace', copy_button=True)
|
||||
|
||||
Reference in New Issue
Block a user