Revision e9b5ecff snf-cyclades-app/synnefo/db/migrations/0077_migrate_networks_to_subnets.py

b/snf-cyclades-app/synnefo/db/migrations/0077_migrate_networks_to_subnets.py
10 10
    def forwards(self, orm):
11 11
        "Write your forwards methods here."
12 12
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
13
        for network in orm.Network.objects.all():
13
        for network in orm.Network.objects.select_related('pool').all():
14 14
            if network.subnet:
15 15
                subnet = orm.Subnet.objects.create(network=network,
16 16
                                                   ipversion=4,
......
18 18
                                                   gateway=network.gateway,
19 19
                                                   dhcp=network.dhcp,
20 20
                                                   deleted=network.deleted)
21
                ip_pool = network.pool
22
                if ip_pool is None:
23
                    ip_pool = orm.IPPoolTable()
24
                ip_pool.subnet = subnet
25
                ip_pool.base = subnet.cidr
26
                ip_pool.offset = 0
27
                ip_pool.size = ipaddr.IPNetwork(network.subnet).numhosts
28
                ip_pool.save()
21

  
22
                if not network.deleted:
23
                    ip_pool = network.pool
24
                    if ip_pool is None:
25
                        ip_pool = orm.IPPoolTable()
26
                    ip_pool.subnet = subnet
27
                    ip_pool.base = subnet.cidr
28
                    ip_pool.offset = 0
29
                    ip_pool.size = ipaddr.IPNetwork(network.subnet).numhosts
30
                    ip_pool.save()
29 31

  
30 32
            if network.subnet6:
31 33
                orm.Subnet.objects.create(network=network,

Also available in: Unified diff