diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2019-11-12 12:54:20 -0500 |
---|---|---|
committer | Brandon Lo <lobrandon1217@gmail.com> | 2020-01-28 13:28:34 -0500 |
commit | 899e1a4baa95d0bc6f0eef34de66f0e257174878 (patch) | |
tree | 2fbc99070b2fe2d75135ca5f899ed14b12639856 /src/resource_inventory/migrations | |
parent | 30a535d7e9bdc0e3cf637207c0c100a16db81586 (diff) |
Begin Resource Refactor
Begins the Resource Refactor by creating new interfaces
to the resources through a Resource super class
and using that new interface in the api
Change-Id: I15a8179bfe915d2cde6d658d056e11cbd2c70e43
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory/migrations')
-rw-r--r-- | src/resource_inventory/migrations/0012_auto_20200103_1850.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/resource_inventory/migrations/0012_auto_20200103_1850.py b/src/resource_inventory/migrations/0012_auto_20200103_1850.py new file mode 100644 index 0000000..2bb203e --- /dev/null +++ b/src/resource_inventory/migrations/0012_auto_20200103_1850.py @@ -0,0 +1,76 @@ +# Generated by Django 2.2 on 2020-01-03 18:50 + +from django.db import migrations, models +import django.db.models.deletion + + +def genTempVlanNetwork(apps, editor): + Vlan = apps.get_model("resource_inventory", "Vlan") + Network = apps.get_model("resource_inventory", "Network") + tempVlanNetwork = apps.get_model("resource_inventory", "tempVlanNetwork") + for vlan in Vlan.objects.filter(network__isnull=False): + tempVlanNetwork.objects.create(network=vlan.network, vlan=vlan) + +def deleteTempVlanNetworks(apps, editor): + tempVlanNetwork = apps.get_model("resource_inventory", "tempVlanNetwork") + tempVlanNetwork.objects.all().delete() + + +def pairVlanPhysicalNetworks(apps, editor): + PhysicalNetwork = apps.get_model("resource_inventory", "PhysicalNetwork") + tempVlanPair = apps.get_model("resource_inventory", "tempVlanNetwork") + for pair in tempVlanPair.objects.all(): + physicalNetwork = PhysicalNetwork.objects.create(vlan_id=vlan.vlan_id, + generic_network=pair.network) + pair.vlan.network = physicalNetwork + +def deletePhysicalNetworks(apps, editor): + PhysicalNetwork = apps.get_model("resource_inventory", "PhysicalNetwork") + PhysicalNetwork.objects.all().delete() + +class Migration(migrations.Migration): + + dependencies = [ + ('resource_inventory', '0011_auto_20191106_2024'), + ] + + operations = [ + migrations.CreateModel( + name='PhysicalNetwork', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('vlan_id', models.IntegerField()), + ('generic_network', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.Network')), + ], + options={ + 'abstract': False, + }, + ), + migrations.AlterField( + model_name='host', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='resourcebundle', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.CreateModel( + name='tempVlanNetwork', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('vlan', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.vlan')), + ('network', models.ForeignKey(null=True, to='resource_inventory.network', on_delete=django.db.models.deletion.CASCADE)), + ] + ), + migrations.RunPython(genTempVlanNetwork, deleteTempVlanNetworks), + migrations.AlterField( + model_name='vlan', + name='network', + field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, + to='resource_inventory.PhysicalNetwork', null=True), + ), + migrations.RunPython(pairVlanPhysicalNetworks, deletePhysicalNetworks), + migrations.DeleteModel("tempVlanNetwork") + ] |