1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Renamed ConsolePort.cs_port to connected_endpoint

This commit is contained in:
Jeremy Stretch
2018-10-24 10:37:54 -04:00
parent ea0de629df
commit 1595a5ecd7
18 changed files with 143 additions and 114 deletions

View File

@@ -1,5 +1,3 @@
# Generated by Django 2.0.8 on 2018-10-18 19:41
from django.db import migrations, models
import django.db.models.deletion
import utilities.fields
@@ -19,13 +17,13 @@ def console_connections_to_cables(apps, schema_editor):
consoleserverport_type = ContentType.objects.get_for_model(ConsoleServerPort)
# Create a new Cable instance from each console connection
for consoleport in ConsolePort.objects.filter(cs_port__isnull=False):
for consoleport in ConsolePort.objects.filter(connected_endpoint__isnull=False):
c = Cable()
# We have to assign GFK fields manually because we're inside a migration.
c.endpoint_a_type = consoleport_type
c.endpoint_a_id = consoleport.id
c.endpoint_b_type = consoleserverport_type
c.endpoint_b_id = consoleport.cs_port_id
c.endpoint_b_id = consoleport.connected_endpoint_id
c.connection_status = consoleport.connection_status
c.save()
@@ -87,6 +85,8 @@ class Migration(migrations.Migration):
]
operations = [
# Create the Cable model
migrations.CreateModel(
name='Cable',
fields=[
@@ -99,8 +99,8 @@ class Migration(migrations.Migration):
('status', models.BooleanField(default=True)),
('label', models.CharField(blank=True, max_length=100)),
('color', utilities.fields.ColorField(blank=True, max_length=6)),
('endpoint_a_type', models.ForeignKey(limit_choices_to={'model__in': ('consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontpanelport', 'rearpanelport')}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
('endpoint_b_type', models.ForeignKey(limit_choices_to={'model__in': ('consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontpanelport', 'rearpanelport')}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
('endpoint_a_type', models.ForeignKey(limit_choices_to={'model__in': ['consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontpanelport', 'rearpanelport']}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
('endpoint_b_type', models.ForeignKey(limit_choices_to={'model__in': ['consoleport', 'consoleserverport', 'interface', 'poweroutlet', 'powerport', 'frontpanelport', 'rearpanelport']}, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.ContentType')),
],
),
migrations.AlterUniqueTogether(
@@ -108,6 +108,23 @@ class Migration(migrations.Migration):
unique_together={('endpoint_b_type', 'endpoint_b_id'), ('endpoint_a_type', 'endpoint_a_id')},
),
# Rename model fields
migrations.RenameField(
model_name='consoleport',
old_name='cs_port',
new_name='connected_endpoint'
),
migrations.AlterField(
model_name='consoleport',
name='connected_endpoint',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='connected_endpoint', to='dcim.ConsoleServerPort'),
),
migrations.AlterField(
model_name='consoleserverport',
name='device',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consoleserverports', to='dcim.Device'),
),
# Copy console/power/interface connections as Cables
migrations.RunPython(console_connections_to_cables),
migrations.RunPython(power_connections_to_cables),