~allenap/maas/xxx-a-thon

« back to all changes in this revision

Viewing changes to src/maasserver/migrations/builtin/maasserver/0044_remove_di_bootresourcefiles.py

  • Committer: Gavin Panella
  • Date: 2016-03-22 21:14:34 UTC
  • mfrom: (4657.1.157 maas)
  • Revision ID: gavin.panella@canonical.com-20160322211434-xzuovio86zvzo2js
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
from __future__ import unicode_literals
 
3
 
 
4
from django.db import (
 
5
    migrations,
 
6
    models,
 
7
)
 
8
 
 
9
# Previous DI file types.
 
10
DI_FILE_TYPES = [
 
11
    'di-kernel',
 
12
    'di-initrd',
 
13
    'di-dtb',
 
14
]
 
15
 
 
16
 
 
17
def remove_di_bootresourcefiles(apps, schema_editor):
 
18
    BootResourceFile = apps.get_model("maasserver", "BootResourceFile")
 
19
    for resource_file in BootResourceFile.objects.filter(
 
20
            filetype__in=DI_FILE_TYPES):
 
21
        # Delete the largefile and content before deleting the resource file
 
22
        # so the post commit hooks are not called in the migration.
 
23
        try:
 
24
            largefile = resource_file.largefile
 
25
        except LargeFile.DoesNotExist:
 
26
            largefile = None
 
27
        if largefile is not None:
 
28
            if largefile.content is not None:
 
29
                largefile.content.unlink()
 
30
            largefile.delete()
 
31
        resource_file.delete()
 
32
 
 
33
 
 
34
class Migration(migrations.Migration):
 
35
 
 
36
    dependencies = [
 
37
        ('maasserver', '0043_dhcpsnippet'),
 
38
    ]
 
39
 
 
40
    operations = [
 
41
        migrations.RunPython(remove_di_bootresourcefiles),
 
42
        migrations.AlterField(
 
43
            model_name='bootresourcefile',
 
44
            name='filetype',
 
45
            field=models.CharField(max_length=20, default='root-tgz', choices=[('root-tgz', 'Root Image (tar.gz)'), ('root-dd', 'Root Compressed DD (dd -> tar.gz)'), ('root-image.gz', 'Compressed Root Image'), ('boot-kernel', 'Linux ISCSI Kernel'), ('boot-initrd', 'Initial ISCSI Ramdisk'), ('boot-dtb', 'ISCSI Device Tree Blob')], editable=False),
 
46
        ),
 
47
    ]