|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from __future__ import unicode_literals |
| 3 | + |
| 4 | +from django.db import migrations, models |
| 5 | +import django.db.models.deletion |
| 6 | + |
| 7 | + |
| 8 | +def forward_func(apps, schema_editor): |
| 9 | + FastdTunnel = apps.get_model('lana_data', 'FastdTunnel') |
| 10 | + FastdTunnelEndpoint = apps.get_model('lana_data', 'FastdTunnelEndpoint') |
| 11 | + Tunnel = apps.get_model('lana_data', 'Tunnel') |
| 12 | + |
| 13 | + fastd_tunnels = Tunnel.objects.filter(protocol='fastd') |
| 14 | + for tunnel in fastd_tunnels: |
| 15 | + fastd = FastdTunnel(tunnel_ptr=tunnel) |
| 16 | + fastd.save() |
| 17 | + for endpoint in [tunnel.endpoint1, tunnel.endpoint2]: |
| 18 | + fastd_endpoint = FastdTunnelEndpoint(tunnelendpoint_ptr=endpoint) |
| 19 | + fastd_endpoint.port = endpoint.port |
| 20 | + fastd_endpoint.public_key = endpoint.public_key |
| 21 | + fastd_endpoint.save() |
| 22 | + |
| 23 | + |
| 24 | +class Migration(migrations.Migration): |
| 25 | + |
| 26 | + dependencies = [ |
| 27 | + ('lana_data', '0002_release'), |
| 28 | + ] |
| 29 | + |
| 30 | + operations = [ |
| 31 | + migrations.CreateModel( |
| 32 | + name='FastdTunnel', |
| 33 | + fields=[ |
| 34 | + ('tunnel_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='lana_data.Tunnel')), |
| 35 | + ], |
| 36 | + ), |
| 37 | + migrations.CreateModel( |
| 38 | + name='FastdTunnelEndpoint', |
| 39 | + fields=[ |
| 40 | + ('tunnelendpoint_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='lana_data.TunnelEndpoint')), |
| 41 | + ('port', models.IntegerField(blank=True, help_text='Defaults to remote AS number if ≤ 65535.', null=True, verbose_name='Port')), |
| 42 | + ('public_key', models.CharField(blank=True, max_length=255, null=True, verbose_name='Public key')), |
| 43 | + ], |
| 44 | + ), |
| 45 | + migrations.RunPython(forward_func), |
| 46 | + migrations.CreateModel( |
| 47 | + name='VtunTunnel', |
| 48 | + fields=[ |
| 49 | + ('tunnel_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='lana_data.Tunnel')), |
| 50 | + ('transport', models.CharField(choices=[('udp', 'udp'), ('tcp', 'tcp')], max_length=3, verbose_name='Transport protocol')), |
| 51 | + ('compression', models.CharField(blank=True, max_length=255, null=True, verbose_name='Compression')), |
| 52 | + ], |
| 53 | + ), |
| 54 | + migrations.CreateModel( |
| 55 | + name='VtunTunnelEndpoint', |
| 56 | + fields=[ |
| 57 | + ('tunnelendpoint_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='lana_data.TunnelEndpoint')), |
| 58 | + ('port', models.IntegerField(blank=True, null=True, verbose_name='Port')), |
| 59 | + ], |
| 60 | + ), |
| 61 | + migrations.RemoveField( |
| 62 | + model_name='tunnel', |
| 63 | + name='protocol', |
| 64 | + ), |
| 65 | + migrations.RemoveField( |
| 66 | + model_name='tunnelendpoint', |
| 67 | + name='port', |
| 68 | + ), |
| 69 | + migrations.RemoveField( |
| 70 | + model_name='tunnelendpoint', |
| 71 | + name='public_key', |
| 72 | + ), |
| 73 | + migrations.AddField( |
| 74 | + model_name='tunnelendpoint', |
| 75 | + name='external_hostname', |
| 76 | + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='External hostname'), |
| 77 | + ), |
| 78 | + ] |
0 commit comments