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