Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / db / migrations / 0035_default_backend.py @ 0c09b1c0

History | View | Annotate | Download (8.8 kB)

1
# encoding: utf-8
2
import datetime
3
from south.db import db
4
from south.v2 import DataMigration
5
from django.db import models
6

    
7
from django.conf import settings
8

    
9
class Migration(DataMigration):
10

    
11
    def forwards(self, orm):
12
        "Write your forwards methods here."
13
        try:
14
            # Do NOT import external code as can be depricated when the
15
            # migration will run
16
            cluster_info = settings.GANETI_CLUSTER_INFO
17
        except (AttributeError, ImportError):
18
            return
19

    
20
        (ip, port, username, password) = cluster_info
21
        backend = orm.Backend.objects.create(clustername = ip,
22
                                             port = port,
23
                                             username = username,
24
                                             password = password)
25
        for vm in orm.VirtualMachine.objects.all():
26
            vm.backend = backend
27
            vm.save()
28

    
29

    
30

    
31

    
32
    def backwards(self, orm):
33
        "Write your backwards methods here."
34
        for vm in orm.VirtualMachine.objects.all():
35
            vm.backend = None
36
            vm.save()
37

    
38

    
39

    
40
    models = {
41
        'db.backend': {
42
            'Meta': {'object_name': 'Backend'},
43
            'clustername': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
44
            'ctotal': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
45
            'dfree': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
46
            'drained': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
47
            'dtotal': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
48
            'hash': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
49
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
50
            'mfree': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
51
            'mtotal': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
52
            'offline': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
53
            'password': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'}),
54
            'pinst_cnt': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
55
            'port': ('django.db.models.fields.PositiveIntegerField', [], {'default': '5080'}),
56
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
57
            'username': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'})
58
        },
59
        'db.flavor': {
60
            'Meta': {'unique_together': "(('cpu', 'ram', 'disk', 'disk_template'),)", 'object_name': 'Flavor'},
61
            'cpu': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
62
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
63
            'disk': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
64
            'disk_template': ('django.db.models.fields.CharField', [], {'default': "'drbd'", 'max_length': '32'}),
65
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
66
            'ram': ('django.db.models.fields.IntegerField', [], {'default': '0'})
67
        },
68
        'db.network': {
69
            'Meta': {'object_name': 'Network'},
70
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
71
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
72
            'link': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['db.NetworkLink']"}),
73
            'machines': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['db.VirtualMachine']", 'through': "orm['db.NetworkInterface']", 'symmetrical': 'False'}),
74
            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
75
            'public': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
76
            'state': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
77
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
78
            'userid': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True'})
79
        },
80
        'db.networkinterface': {
81
            'Meta': {'object_name': 'NetworkInterface'},
82
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
83
            'firewall_profile': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
84
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
85
            'index': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
86
            'ipv4': ('django.db.models.fields.CharField', [], {'max_length': '15', 'null': 'True'}),
87
            'ipv6': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True'}),
88
            'mac': ('django.db.models.fields.CharField', [], {'max_length': '17', 'null': 'True'}),
89
            'machine': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'nics'", 'to': "orm['db.VirtualMachine']"}),
90
            'network': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'nics'", 'to': "orm['db.Network']"}),
91
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
92
        },
93
        'db.networklink': {
94
            'Meta': {'object_name': 'NetworkLink'},
95
            'available': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
96
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
97
            'index': ('django.db.models.fields.IntegerField', [], {}),
98
            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
99
            'network': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'null': 'True', 'to': "orm['db.Network']"})
100
        },
101
        'db.virtualmachine': {
102
            'Meta': {'object_name': 'VirtualMachine'},
103
            'action': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
104
            'backend': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'virtual_machines'", 'null': 'True', 'to': "orm['db.Backend']"}),
105
            'backend_hash': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}),
106
            'backendjobid': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
107
            'backendjobstatus': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
108
            'backendlogmsg': ('django.db.models.fields.TextField', [], {'null': 'True'}),
109
            'backendopcode': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
110
            'backendtime': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(1, 1, 1, 0, 0)'}),
111
            'buildpercentage': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
112
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
113
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
114
            'flavor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['db.Flavor']"}),
115
            'hostid': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
116
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
117
            'imageid': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
118
            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
119
            'operstate': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
120
            'suspended': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
121
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
122
            'userid': ('django.db.models.fields.CharField', [], {'max_length': '100'})
123
        },
124
        'db.virtualmachinemetadata': {
125
            'Meta': {'unique_together': "(('meta_key', 'vm'),)", 'object_name': 'VirtualMachineMetadata'},
126
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
127
            'meta_key': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
128
            'meta_value': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
129
            'vm': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'metadata'", 'to': "orm['db.VirtualMachine']"})
130
        }
131
    }
132

    
133
    complete_apps = ['db']