diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index ecb2d7c1e..83e7aa470 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -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 = [] diff --git a/netbox/virtualization/choices.py b/netbox/virtualization/choices.py index 1dae88e1d..3795ddb76 100644 --- a/netbox/virtualization/choices.py +++ b/netbox/virtualization/choices.py @@ -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'), - ) diff --git a/netbox/virtualization/forms.py b/netbox/virtualization/forms.py index ab0e10f04..e2ff841bf 100644 --- a/netbox/virtualization/forms.py +++ b/netbox/virtualization/forms.py @@ -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( diff --git a/netbox/virtualization/migrations/0015_vminterface.py b/netbox/virtualization/migrations/0015_vminterface.py index fcda6b4f3..6c5207226 100644 --- a/netbox/virtualization/migrations/0015_vminterface.py +++ b/netbox/virtualization/migrations/0015_vminterface.py @@ -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={ diff --git a/netbox/virtualization/migrations/0016_replicate_interfaces.py b/netbox/virtualization/migrations/0016_replicate_interfaces.py index 2df483e78..d6c0b0217 100644 --- a/netbox/virtualization/migrations/0016_replicate_interfaces.py +++ b/netbox/virtualization/migrations/0016_replicate_interfaces.py @@ -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() diff --git a/netbox/virtualization/models.py b/netbox/virtualization/models.py index bed198326..4a753561a 100644 --- a/netbox/virtualization/models.py +++ b/netbox/virtualization/models.py @@ -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() diff --git a/netbox/virtualization/tests/test_filters.py b/netbox/virtualization/tests/test_filters.py index 821127b92..ad452ec51 100644 --- a/netbox/virtualization/tests/test_filters.py +++ b/netbox/virtualization/tests/test_filters.py @@ -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