Commit 03f5d4bb authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Speedup db data migrations

parent c024d130
......@@ -10,7 +10,7 @@ class Migration(DataMigration):
def forwards(self, orm):
"Write your forwards methods here."
# Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
for network in orm.Network.objects.all():
for network in orm.Network.objects.select_related('pool').all():
if network.subnet:
subnet = orm.Subnet.objects.create(network=network,
ipversion=4,
......@@ -18,14 +18,16 @@ class Migration(DataMigration):
gateway=network.gateway,
dhcp=network.dhcp,
deleted=network.deleted)
ip_pool = network.pool
if ip_pool is None:
ip_pool = orm.IPPoolTable()
ip_pool.subnet = subnet
ip_pool.base = subnet.cidr
ip_pool.offset = 0
ip_pool.size = ipaddr.IPNetwork(network.subnet).numhosts
ip_pool.save()
if not network.deleted:
ip_pool = network.pool
if ip_pool is None:
ip_pool = orm.IPPoolTable()
ip_pool.subnet = subnet
ip_pool.base = subnet.cidr
ip_pool.offset = 0
ip_pool.size = ipaddr.IPNetwork(network.subnet).numhosts
ip_pool.save()
if network.subnet6:
orm.Subnet.objects.create(network=network,
......
......@@ -11,7 +11,8 @@ class Migration(DataMigration):
# Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
# Delete stale NICs
orm.NetworkInterface.objects.filter(machine__deleted=True).delete()
for nic in orm.NetworkInterface.objects.all():
for nic in orm.NetworkInterface.objects.select_related('machine',
'network').all():
userid = nic.machine.userid
nic.userid = userid
nic.save()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment