mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 09:53:34 -06:00
Rename 'vm_interface' to 'vminterface'; misc cleanup
This commit is contained in:
parent
d6386f739e
commit
6663844a86
@ -1200,7 +1200,7 @@ class ServiceForm(BootstrapMixin, CustomFieldModelForm):
|
||||
)
|
||||
elif self.instance.virtual_machine:
|
||||
self.fields['ipaddresses'].queryset = IPAddress.objects.filter(
|
||||
vm_interface__in=self.instance.virtual_machine.interfaces.values_list('id', flat=True)
|
||||
vminterface__in=self.instance.virtual_machine.interfaces.values_list('id', flat=True)
|
||||
)
|
||||
else:
|
||||
self.fields['ipaddresses'].choices = []
|
||||
|
@ -1,4 +1,3 @@
|
||||
from dcim.choices import InterfaceTypeChoices
|
||||
from utilities.choices import ChoiceSet
|
||||
|
||||
|
||||
@ -29,16 +28,3 @@ class VirtualMachineStatusChoices(ChoiceSet):
|
||||
STATUS_ACTIVE: 1,
|
||||
STATUS_STAGED: 3,
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Interface types (for VirtualMachines)
|
||||
#
|
||||
|
||||
class VMInterfaceTypeChoices(ChoiceSet):
|
||||
|
||||
TYPE_VIRTUAL = InterfaceTypeChoices.TYPE_VIRTUAL
|
||||
|
||||
CHOICES = (
|
||||
(TYPE_VIRTUAL, 'Virtual'),
|
||||
)
|
||||
|
@ -3,7 +3,7 @@ from django.core.exceptions import ValidationError
|
||||
|
||||
from dcim.choices import InterfaceModeChoices
|
||||
from dcim.constants import INTERFACE_MTU_MAX, INTERFACE_MTU_MIN
|
||||
from dcim.forms import INTERFACE_MODE_HELP_TEXT, InterfaceCommonForm
|
||||
from dcim.forms import INTERFACE_MODE_HELP_TEXT
|
||||
from dcim.models import Device, DeviceRole, Platform, Rack, Region, Site
|
||||
from extras.forms import (
|
||||
AddRemoveTagsForm, CustomFieldBulkEditForm, CustomFieldModelCSVForm, CustomFieldModelForm, CustomFieldFilterForm,
|
||||
@ -357,7 +357,7 @@ class VirtualMachineForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
# Collect interface IPs
|
||||
interface_ips = IPAddress.objects.prefetch_related('interface').filter(
|
||||
address__family=family,
|
||||
vm_interface__in=self.instance.interfaces.values_list('id', flat=True)
|
||||
vminterface__in=self.instance.interfaces.values_list('id', flat=True)
|
||||
)
|
||||
if interface_ips:
|
||||
ip_choices.append(
|
||||
@ -368,7 +368,7 @@ class VirtualMachineForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
# Collect NAT IPs
|
||||
nat_ips = IPAddress.objects.prefetch_related('nat_inside').filter(
|
||||
address__family=family,
|
||||
nat_inside__vm_interface__in=self.instance.interfaces.values_list('id', flat=True)
|
||||
nat_inside__vminterface__in=self.instance.interfaces.values_list('id', flat=True)
|
||||
)
|
||||
if nat_ips:
|
||||
ip_choices.append(
|
||||
|
@ -30,9 +30,9 @@ class Migration(migrations.Migration):
|
||||
('mtu', models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(65536)])),
|
||||
('mode', models.CharField(blank=True, max_length=50)),
|
||||
('description', models.CharField(blank=True, max_length=200)),
|
||||
('tagged_vlans', models.ManyToManyField(blank=True, related_name='vm_interfaces_as_tagged', to='ipam.VLAN')),
|
||||
('tags', taggit.managers.TaggableManager(related_name='vm_interface', through='extras.TaggedItem', to='extras.Tag')),
|
||||
('untagged_vlan', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='vm_interfaces_as_untagged', to='ipam.VLAN')),
|
||||
('tagged_vlans', models.ManyToManyField(blank=True, related_name='vminterfaces_as_tagged', to='ipam.VLAN')),
|
||||
('tags', taggit.managers.TaggableManager(related_name='vminterface', through='extras.TaggedItem', to='extras.Tag')),
|
||||
('untagged_vlan', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='vminterfaces_as_untagged', to='ipam.VLAN')),
|
||||
('virtual_machine', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='interfaces', to='virtualization.VirtualMachine')),
|
||||
],
|
||||
options={
|
||||
|
@ -16,7 +16,7 @@ def replicate_interfaces(apps, schema_editor):
|
||||
# Replicate dcim.Interface instances assigned to VirtualMachines
|
||||
original_interfaces = Interface.objects.filter(virtual_machine__isnull=False)
|
||||
for interface in original_interfaces:
|
||||
vm_interface = VMInterface(
|
||||
vminterface = VMInterface(
|
||||
virtual_machine=interface.virtual_machine,
|
||||
name=interface.name,
|
||||
enabled=interface.enabled,
|
||||
@ -26,22 +26,22 @@ def replicate_interfaces(apps, schema_editor):
|
||||
description=interface.description,
|
||||
untagged_vlan=interface.untagged_vlan,
|
||||
)
|
||||
vm_interface.save()
|
||||
vminterface.save()
|
||||
|
||||
# Copy tagged VLANs
|
||||
vm_interface.tagged_vlans.set(interface.tagged_vlans.all())
|
||||
vminterface.tagged_vlans.set(interface.tagged_vlans.all())
|
||||
|
||||
# Reassign tags to the new instance
|
||||
TaggedItem.objects.filter(
|
||||
content_type=interface_ct, object_id=interface.pk
|
||||
).update(
|
||||
content_type=vminterface_ct, object_id=vm_interface.pk
|
||||
content_type=vminterface_ct, object_id=vminterface.pk
|
||||
)
|
||||
|
||||
# Update any assigned IPAddresses
|
||||
IPAddress.objects.filter(assigned_object_id=interface.pk).update(
|
||||
assigned_object_type=vminterface_ct,
|
||||
assigned_object_id=vm_interface.pk
|
||||
assigned_object_id=vminterface.pk
|
||||
)
|
||||
|
||||
replicated_count = VMInterface.objects.count()
|
||||
|
@ -394,14 +394,14 @@ class VMInterface(BaseInterface):
|
||||
untagged_vlan = models.ForeignKey(
|
||||
to='ipam.VLAN',
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='vm_interfaces_as_untagged',
|
||||
related_name='vminterfaces_as_untagged',
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name='Untagged VLAN'
|
||||
)
|
||||
tagged_vlans = models.ManyToManyField(
|
||||
to='ipam.VLAN',
|
||||
related_name='vm_interfaces_as_tagged',
|
||||
related_name='vminterfaces_as_tagged',
|
||||
blank=True,
|
||||
verbose_name='Tagged VLANs'
|
||||
)
|
||||
@ -409,11 +409,11 @@ class VMInterface(BaseInterface):
|
||||
to='ipam.IPAddress',
|
||||
content_type_field='assigned_object_type',
|
||||
object_id_field='assigned_object_id',
|
||||
related_query_name='vm_interface'
|
||||
related_query_name='vminterface'
|
||||
)
|
||||
tags = TaggableManager(
|
||||
through=TaggedItem,
|
||||
related_name='vm_interface'
|
||||
related_name='vminterface'
|
||||
)
|
||||
|
||||
objects = RestrictedQuerySet.as_manager()
|
||||
|
@ -365,7 +365,7 @@ class VirtualMachineTestCase(TestCase):
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
class InterfaceTestCase(TestCase):
|
||||
class VMInterfaceTestCase(TestCase):
|
||||
queryset = VMInterface.objects.all()
|
||||
filterset = VMInterfaceFilterSet
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user