From d73588dfe1066f85bb83df0e3c0881ff42c25e04 Mon Sep 17 00:00:00 2001 From: Parker Berberian Date: Tue, 18 Feb 2020 13:17:10 -0500 Subject: Add Migration Files Adds migration files with some custom logic to accompany the refactoring in resource_inventory. Change-Id: Id3b3e46913c1f9a102426a5c33d7a282f46e8b28 Signed-off-by: Parker Berberian --- src/api/migrations/0011_auto_20200218_1536.py | 54 +++ src/api/migrations/0012_manual_20200220.py | 18 + .../0007_remove_booking_config_bundle.py | 17 + .../migrations/0013_auto_20200218_1536.py | 449 +++++++++++++++++++++ 4 files changed, 538 insertions(+) create mode 100644 src/api/migrations/0011_auto_20200218_1536.py create mode 100644 src/api/migrations/0012_manual_20200220.py create mode 100644 src/booking/migrations/0007_remove_booking_config_bundle.py create mode 100644 src/resource_inventory/migrations/0013_auto_20200218_1536.py diff --git a/src/api/migrations/0011_auto_20200218_1536.py b/src/api/migrations/0011_auto_20200218_1536.py new file mode 100644 index 0000000..a399495 --- /dev/null +++ b/src/api/migrations/0011_auto_20200218_1536.py @@ -0,0 +1,54 @@ +# Generated by Django 2.2 on 2020-02-18 15:36 + +from django.db import migrations, models + + +def set_resource_id(apps, schema_editor): + for cls in ["HardwareConfig", "NetworkConfig", "SnapshotConfig"]: + model = apps.get_model('api', cls) + for m in model.objects.all(): + m.resource_id = m.host.labid + m.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0010_auto_20191219_2004'), + # ('resource_inventory', '0013_auto_20200218_1536') + ] + + operations = [ + migrations.AddField( + model_name='hosthardwarerelation', + name='resource_id', + field=models.CharField(default='default_id', max_length=200), + ), + migrations.AddField( + model_name='hostnetworkrelation', + name='resource_id', + field=models.CharField(default='default_id', max_length=200), + ), + migrations.AddField( + model_name='snapshotconfig', + name='resource_id', + field=models.CharField(default='default_id', max_length=200), + ), + migrations.RunPython(set_resource_id), + migrations.RemoveField( + model_name='hosthardwarerelation', + name='host', + ), + migrations.RemoveField( + model_name='hostnetworkrelation', + name='host', + ), + migrations.RemoveField( + model_name='snapshotconfig', + name='host', + ), + migrations.RemoveField( + model_name='opnfvapiconfig', + name='roles', + ), + ] diff --git a/src/api/migrations/0012_manual_20200220.py b/src/api/migrations/0012_manual_20200220.py new file mode 100644 index 0000000..40f7e79 --- /dev/null +++ b/src/api/migrations/0012_manual_20200220.py @@ -0,0 +1,18 @@ + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0011_auto_20200218_1536'), + ('resource_inventory', '0013_auto_20200218_1536') + ] + + operations = [ + migrations.AddField( + model_name='opnfvapiconfig', + name='roles', + field=models.ManyToManyField(to='resource_inventory.ResourceOPNFVConfig'), + ), + ] diff --git a/src/booking/migrations/0007_remove_booking_config_bundle.py b/src/booking/migrations/0007_remove_booking_config_bundle.py new file mode 100644 index 0000000..dcd2e1c --- /dev/null +++ b/src/booking/migrations/0007_remove_booking_config_bundle.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2 on 2020-02-18 15:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('booking', '0006_booking_opnfv_config'), + ] + + operations = [ + migrations.RemoveField( + model_name='booking', + name='config_bundle', + ), + ] diff --git a/src/resource_inventory/migrations/0013_auto_20200218_1536.py b/src/resource_inventory/migrations/0013_auto_20200218_1536.py new file mode 100644 index 0000000..3049dc7 --- /dev/null +++ b/src/resource_inventory/migrations/0013_auto_20200218_1536.py @@ -0,0 +1,449 @@ +# Generated by Django 2.2 on 2020-02-18 15:36 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import resource_inventory.models + + +def populate_servers(apps, schema_editor): + """Convert old Host models to Server Resources.""" + Host = apps.get_model('resource_inventory', 'Host') + Server = apps.get_model('resource_inventory', 'Server') + for h in Host.objects.all(): + Server.objects.create( + working=h.working, + vendor=h.vendor, + labid=h.labid, + booked=h.booked, + name=h.labid + ) + + +def populate_resource_templates(apps, schema_editor): + """ + Convert old GenericResourceBundles to ResourceTemplate. + + This will be kept blank for now. If, during testing, we realize + we want to implement this, we will. For now, it seems + fine to let the old models just die and create + new ones as needed. + """ + pass + + +def populate_resource_profiles(apps, schema_editor): + """ + Convert old HostProfile models to ResourceProfiles. + + Also updates all the foreign keys pointed to the old + host profile. This change was basically only a name change. + """ + HostProfile = apps.get_model('resource_inventory', 'HostProfile') + ResourceProfile = apps.get_model('resource_inventory', 'ResourceProfile') + for hp in HostProfile.objects.all(): + rp = ResourceProfile.objects.create(name=hp.name, description=hp.description) + rp.labs.add(*list(hp.labs.all())) + rp.interfaceprofile = hp.interfaceprofile + rp.storageprofile = hp.storageprofile + rp.cpuprofile = hp.cpuprofile + rp.ramprofile = hp.ramprofile + rp.save() + rp.interfaceprofile.host = rp + rp.storageprofile.host = rp + rp.cpuprofile.host = rp + rp.ramprofile.host = rp + rp.interfaceprofile.save() + rp.storageprofile.save() + rp.cpuprofile.save() + rp.ramprofile.save() + + +class Migration(migrations.Migration): + """TODO: Creation of the following models. + + - Server + - ResourceTemplate + - ResourceProfile + - ResourceConfiguration (?) + - InterfaceConfiguration (?) + + And set the correct defaults for the following fields: + - Interface.profile + - OpnfvConfig.template (?) + - physicalnetwork.lab + - physicalnetwork.profile + """ + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('booking', '0007_remove_booking_config_bundle'), + ('account', '0004_downtime'), + ('api', '0011_auto_20200218_1536'), + ('resource_inventory', '0012_auto_20200103_1850'), + ] + + operations = [ + migrations.CreateModel( + name='InterfaceConfiguration', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('connections', models.ManyToManyField(to='resource_inventory.NetworkConnection')), + ], + ), + migrations.CreateModel( + name='ResourceConfiguration', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('is_head_node', models.BooleanField(default=False)), + ], + ), + migrations.CreateModel( + name='ResourceOPNFVConfig', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + migrations.CreateModel( + name='ResourceProfile', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=200, unique=True)), + ('description', models.TextField()), + ('labs', models.ManyToManyField(related_name='resourceprofiles', to='account.Lab')), + ], + ), + migrations.RunPython(populate_resource_profiles), + migrations.CreateModel( + name='ResourceTemplate', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=300, unique=True)), + ('xml', models.TextField()), + ('description', models.CharField(default='', max_length=1000)), + ('public', models.BooleanField(default=False)), + ('hidden', models.BooleanField(default=False)), + ('lab', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resourcetemplates', to='account.Lab')), + ('owner', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.RunPython(populate_resource_templates), + migrations.CreateModel( + name='Server', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('working', models.BooleanField(default=True)), + ('vendor', models.CharField(default='unknown', max_length=100)), + ('model', models.CharField(default='unknown', max_length=150)), + ('labid', models.CharField(default='default_id', max_length=200, unique=True)), + ('booked', models.BooleanField(default=False)), + ('name', models.CharField(max_length=200, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.RunPython(populate_servers), + migrations.RemoveField( + model_name='generichost', + name='profile', + ), + migrations.RemoveField( + model_name='generichost', + name='resource', + ), + migrations.RemoveField( + model_name='genericinterface', + name='connections', + ), + migrations.RemoveField( + model_name='genericinterface', + name='host', + ), + migrations.RemoveField( + model_name='genericinterface', + name='profile', + ), + migrations.RemoveField( + model_name='genericresource', + name='bundle', + ), + migrations.RemoveField( + model_name='genericresourcebundle', + name='lab', + ), + migrations.RemoveField( + model_name='genericresourcebundle', + name='owner', + ), + migrations.RemoveField( + model_name='host', + name='bundle', + ), + migrations.RemoveField( + model_name='host', + name='config', + ), + migrations.RemoveField( + model_name='host', + name='lab', + ), + migrations.RemoveField( + model_name='host', + name='profile', + ), + migrations.RemoveField( + model_name='host', + name='remote_management', + ), + migrations.RemoveField( + model_name='host', + name='template', + ), + migrations.RemoveField( + model_name='hostconfiguration', + name='bundle', + ), + migrations.RemoveField( + model_name='hostconfiguration', + name='host', + ), + migrations.RemoveField( + model_name='hostconfiguration', + name='image', + ), + migrations.RemoveField( + model_name='hostopnfvconfig', + name='host_config', + ), + migrations.RemoveField( + model_name='hostopnfvconfig', + name='opnfv_config', + ), + migrations.RemoveField( + model_name='hostopnfvconfig', + name='role', + ), + migrations.RemoveField( + model_name='hostprofile', + name='labs', + ), + migrations.RemoveField( + model_name='interface', + name='host', + ), + migrations.RemoveField( + model_name='interface', + name='name', + ), + migrations.RemoveField( + model_name='opnfvconfig', + name='bundle', + ), + migrations.AddField( + model_name='interface', + name='profile', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.InterfaceProfile'), + preserve_default=False, + ), + migrations.AddField( + model_name='interfaceprofile', + name='order', + field=models.IntegerField(default=-1), + ), + migrations.AddField( + model_name='physicalnetwork', + name='bundle', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.ResourceBundle'), + ), + migrations.AddField( + model_name='physicalnetwork', + name='interfaces', + field=models.ManyToManyField(to='resource_inventory.Interface'), + ), + migrations.AddField( + model_name='physicalnetwork', + name='lab', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='account.Lab'), + preserve_default=False, + ), + migrations.AddField( + model_name='physicalnetwork', + name='labid', + field=models.CharField(default='default_id', max_length=200, unique=True), + ), + migrations.AddField( + model_name='physicalnetwork', + name='model', + field=models.CharField(default='unknown', max_length=150), + ), + migrations.AddField( + model_name='physicalnetwork', + name='remote_management', + field=models.ForeignKey(default=resource_inventory.models.get_default_remote_info, on_delete=models.SET(resource_inventory.models.get_default_remote_info), to='resource_inventory.RemoteInfo'), + ), + migrations.AddField( + model_name='physicalnetwork', + name='vendor', + field=models.CharField(default='unknown', max_length=100), + ), + migrations.AddField( + model_name='physicalnetwork', + name='working', + field=models.BooleanField(default=True), + ), + migrations.AlterField( + model_name='cpuprofile', + name='host', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cpuprofile', to='resource_inventory.ResourceProfile'), + ), + migrations.AlterField( + model_name='diskprofile', + name='host', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='storageprofile', to='resource_inventory.ResourceProfile'), + ), + migrations.AlterField( + model_name='image', + name='host_type', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.ResourceProfile'), + ), + migrations.AlterField( + model_name='interfaceprofile', + name='host', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='interfaceprofile', to='resource_inventory.ResourceProfile'), + ), + migrations.AlterField( + model_name='network', + name='bundle', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='networks', to='resource_inventory.ResourceTemplate'), + ), + migrations.AlterField( + model_name='ramprofile', + name='host', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ramprofile', to='resource_inventory.ResourceProfile'), + ), + migrations.AlterField( + model_name='resourcebundle', + name='template', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.ResourceTemplate'), + ), + migrations.DeleteModel( + name='ConfigBundle', + ), + migrations.DeleteModel( + name='GenericHost', + ), + migrations.DeleteModel( + name='GenericInterface', + ), + migrations.DeleteModel( + name='GenericResource', + ), + migrations.DeleteModel( + name='GenericResourceBundle', + ), + migrations.DeleteModel( + name='Host', + ), + migrations.DeleteModel( + name='HostConfiguration', + ), + migrations.DeleteModel( + name='HostOPNFVConfig', + ), + migrations.DeleteModel( + name='HostProfile', + ), + migrations.AddField( + model_name='server', + name='bundle', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.ResourceBundle'), + ), + migrations.AddField( + model_name='server', + name='config', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.ResourceConfiguration'), + ), + migrations.AddField( + model_name='server', + name='interfaces', + field=models.ManyToManyField(to='resource_inventory.Interface'), + ), + migrations.AddField( + model_name='server', + name='lab', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.Lab'), + ), + migrations.AddField( + model_name='server', + name='profile', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.ResourceProfile'), + ), + migrations.AddField( + model_name='server', + name='remote_management', + field=models.ForeignKey(default=resource_inventory.models.get_default_remote_info, on_delete=models.SET(resource_inventory.models.get_default_remote_info), to='resource_inventory.RemoteInfo'), + ), + migrations.AddField( + model_name='resourceopnfvconfig', + name='opnfv_config', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='resource_opnfv_config', to='resource_inventory.OPNFVConfig'), + ), + migrations.AddField( + model_name='resourceopnfvconfig', + name='resource_config', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='resource_opnfv_config', to='resource_inventory.ResourceConfiguration'), + ), + migrations.AddField( + model_name='resourceopnfvconfig', + name='role', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='resource_opnfv_configs', to='resource_inventory.OPNFVRole'), + ), + migrations.AddField( + model_name='resourceconfiguration', + name='image', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='resource_inventory.Image'), + ), + migrations.AddField( + model_name='resourceconfiguration', + name='profile', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.ResourceProfile'), + ), + migrations.AddField( + model_name='resourceconfiguration', + name='template', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='resourceConfigurations', to='resource_inventory.ResourceTemplate'), + ), + migrations.AddField( + model_name='interfaceconfiguration', + name='profile', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.InterfaceProfile'), + ), + migrations.AddField( + model_name='interfaceconfiguration', + name='resource_config', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='interface_configs', to='resource_inventory.ResourceConfiguration'), + ), + migrations.AddField( + model_name='interface', + name='acts_as', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.InterfaceConfiguration'), + ), + migrations.AddField( + model_name='opnfvconfig', + name='template', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='opnfv_config', to='resource_inventory.ResourceTemplate'), + preserve_default=False, + ), + migrations.AddField( + model_name='physicalnetwork', + name='config', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='resource_inventory.ResourceConfiguration'), + ), + migrations.AddField( + model_name='physicalnetwork', + name='profile', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='resource_inventory.ResourceProfile'), + preserve_default=False, + ), + ] -- cgit 1.2.3-korg