<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


def copy_external_ips(apps, schema_editor):
    Instance = apps.get_model('openstack_tenant', 'Instance')
    FloatingIP = apps.get_model('openstack_tenant', 'FloatingIP')

    for instance in Instance.objects.iterator():
        floating_ip = FloatingIP.objects.filter(
            settings=instance.service_project_link.service.settings,
            address=instance.external_ips,
        ).first()

        if floating_ip:
            instance.external_ip = floating_ip
            instance.save()


class Migration(migrations.Migration):

    dependencies = [
        ('openstack_tenant', '0017_snapshot_schedule'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='instance',
            name='internal_ips',
        ),
        migrations.AddField(
            model_name='instance',
            name='external_ip',
            field=models.OneToOneField(related_name='instance', to='openstack_tenant.FloatingIP', blank=True, null=True, on_delete=models.SET_NULL),
        ),
        migrations.RunPython(copy_external_ips),
    ]
<commit_msg>Rearrange migration operations call [WAL-336]<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


def copy_external_ips(apps, schema_editor):
    Instance = apps.get_model('openstack_tenant', 'Instance')
    FloatingIP = apps.get_model('openstack_tenant', 'FloatingIP')

    for instance in Instance.objects.iterator():
        floating_ip = FloatingIP.objects.filter(
            settings=instance.service_project_link.service.settings,
            address=instance.external_ips,
        ).first()

        if floating_ip:
            instance.external_ip = floating_ip
            instance.save()


class Migration(migrations.Migration):

    dependencies = [
        ('openstack_tenant', '0017_snapshot_schedule'),
    ]

    operations = [
        migrations.RunPython(copy_external_ips),
        migrations.RemoveField(
            model_name='instance',
            name='internal_ips',
        ),
        migrations.AddField(
            model_name='instance',
            name='external_ip',
            field=models.OneToOneField(related_name='instance', to='openstack_tenant.FloatingIP', blank=True, null=True, on_delete=models.SET_NULL),
        ),
    ]

{'fraction_non_alphanumeric': 0.10705496308449548, 'fraction_numerical': 0.005332239540607055, 'mean_word_length': 2.8961661341853033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3321317', 'n_tokens_mistral': 689, 'n_tokens_neox': 694, 'n_words': 110}