Rename 'vm_interface' to 'vminterface'; misc cleanup

This commit is contained in:
Jeremy Stretch
2020-06-24 09:27:30 -04:00
parent d6386f739e
commit 6663844a86
7 changed files with 17 additions and 31 deletions
@@ -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()