Revision d484f6df

b/snf-cyclades-app/synnefo/db/migrations/0080_nics_to_ips.py
1
# -*- coding: 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
class Migration(DataMigration):
8

  
9
    def forwards(self, orm):
10
        "Write your forwards methods here."
11
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
12
        for nic in orm.NetworkInterface.objects.all():
13
            userid = nic.machine.userid
14
            nic.userid = userid
15
            nic.save()
16
            network = nic.network
17
            for attr in ["ipv4", "ipv6"]:
18
                address = getattr(nic, attr)
19
                if address:
20
                    ipversion = 4 if attr == "ipv4" else 6
21
                    subnet = nic.network.subnets.get(ipversion=ipversion)
22
                    orm.IPAddress.objects.create(network=network,
23
                                                 subnet=subnet,
24
                                                 nic=nic,
25
                                                 userid=userid,
26
                                                 address=address)
27

  
28

  
29
    def backwards(self, orm):
30
        "Write your backwards methods here."
31
        for ip in orm.IPAddress.objects.filter(deleted=False):
32
            nic = ip.nic
33
            attr = "ipv4" if nic.subnet.ipversion == 4 else "ipv6"
34
            setattr(nic, attr, ip.address)
35
            nic.save()
36

  
37

  
38
    models = {
39
        'db.backend': {
40
            'Meta': {'ordering': "['clustername']", 'object_name': 'Backend'},
41
            'clustername': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
42
            'ctotal': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
43
            'dfree': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
44
            'disk_templates': ('synnefo.db.fields.SeparatedValuesField', [], {'null': 'True'}),
45
            'drained': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
46
            'dtotal': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
47
            'hash': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
48
            'hypervisor': ('django.db.models.fields.CharField', [], {'default': "'kvm'", 'max_length': '32'}),
49
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
50
            'index': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0', 'unique': 'True'}),
51
            'mfree': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
52
            'mtotal': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
53
            'offline': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
54
            'password_hash': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
55
            'pinst_cnt': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
56
            'port': ('django.db.models.fields.PositiveIntegerField', [], {'default': '5080'}),
57
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
58
            'username': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'})
59
        },
60
        'db.backendnetwork': {
61
            'Meta': {'unique_together': "(('network', 'backend'),)", 'object_name': 'BackendNetwork'},
62
            'backend': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'networks'", 'on_delete': 'models.PROTECT', 'to': "orm['db.Backend']"}),
63
            'backendjobid': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
64
            'backendjobstatus': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
65
            'backendlogmsg': ('django.db.models.fields.TextField', [], {'null': 'True'}),
66
            'backendopcode': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
67
            'backendtime': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(1, 1, 1, 0, 0)'}),
68
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
69
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
70
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
71
            'mac_prefix': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
72
            'network': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'backend_networks'", 'to': "orm['db.Network']"}),
73
            'operstate': ('django.db.models.fields.CharField', [], {'default': "'PENDING'", 'max_length': '30'}),
74
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
75
        },
76
        'db.bridgepooltable': {
77
            'Meta': {'object_name': 'BridgePoolTable'},
78
            'available_map': ('django.db.models.fields.TextField', [], {'default': "''"}),
79
            'base': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
80
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
81
            'offset': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
82
            'reserved_map': ('django.db.models.fields.TextField', [], {'default': "''"}),
83
            'size': ('django.db.models.fields.IntegerField', [], {})
84
        },
85
        'db.flavor': {
86
            'Meta': {'unique_together': "(('cpu', 'ram', 'disk', 'disk_template'),)", 'object_name': 'Flavor'},
87
            'cpu': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
88
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
89
            'disk': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
90
            'disk_template': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
91
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
92
            'ram': ('django.db.models.fields.IntegerField', [], {'default': '0'})
93
        },
94
        'db.floatingip': {
95
            'Meta': {'object_name': 'FloatingIP'},
96
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
97
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
98
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
99
            'ipv4': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15', 'db_index': 'True'}),
100
            'machine': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'floating_ips'", 'null': 'True', 'to': "orm['db.VirtualMachine']"}),
101
            'network': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'floating_ips'", 'to': "orm['db.Network']"}),
102
            'serial': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'floating_ips'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['db.QuotaHolderSerial']"}),
103
            'userid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'})
104
        },
105
        'db.ipaddress': {
106
            'Meta': {'unique_together': "(('network', 'address'),)", 'object_name': 'IPAddress'},
107
            'address': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
108
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
109
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
110
            'floating_ip': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
111
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
112
            'network': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ips'", 'to': "orm['db.Network']"}),
113
            'nic': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ips'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['db.NetworkInterface']"}),
114
            'serial': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ips'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['db.QuotaHolderSerial']"}),
115
            'subnet': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ips'", 'to': "orm['db.Subnet']"}),
116
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
117
            'userid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'})
118
        },
119
        'db.ippooltable': {
120
            'Meta': {'object_name': 'IPPoolTable'},
121
            'available_map': ('django.db.models.fields.TextField', [], {'default': "''"}),
122
            'base': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
123
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
124
            'offset': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
125
            'reserved_map': ('django.db.models.fields.TextField', [], {'default': "''"}),
126
            'size': ('django.db.models.fields.IntegerField', [], {}),
127
            'subnet': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ip_pools'", 'null': 'True', 'to': "orm['db.Subnet']"})
128
        },
129
        'db.macprefixpooltable': {
130
            'Meta': {'object_name': 'MacPrefixPoolTable'},
131
            'available_map': ('django.db.models.fields.TextField', [], {'default': "''"}),
132
            'base': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
133
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
134
            'offset': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
135
            'reserved_map': ('django.db.models.fields.TextField', [], {'default': "''"}),
136
            'size': ('django.db.models.fields.IntegerField', [], {})
137
        },
138
        'db.network': {
139
            'Meta': {'object_name': 'Network'},
140
            'action': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '32', 'null': 'True'}),
141
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
142
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
143
            'drained': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
144
            'external_router': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
145
            'flavor': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
146
            'floating_ip_pool': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
147
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
148
            'link': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
149
            'mac_prefix': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
150
            'machines': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['db.VirtualMachine']", 'through': "orm['db.NetworkInterface']", 'symmetrical': 'False'}),
151
            'mode': ('django.db.models.fields.CharField', [], {'max_length': '16', 'null': 'True'}),
152
            'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
153
            'public': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
154
            'serial': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'network'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['db.QuotaHolderSerial']"}),
155
            'state': ('django.db.models.fields.CharField', [], {'default': "'PENDING'", 'max_length': '32'}),
156
            'tags': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}),
157
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
158
            'userid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'db_index': 'True'})
159
        },
160
        'db.networkinterface': {
161
            'Meta': {'object_name': 'NetworkInterface'},
162
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
163
            'device_owner': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}),
164
            'dirty': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
165
            'firewall_profile': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
166
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
167
            'index': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
168
            'ipv4': ('django.db.models.fields.CharField', [], {'max_length': '15', 'null': 'True'}),
169
            'ipv6': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True'}),
170
            'mac': ('django.db.models.fields.CharField', [], {'max_length': '32', 'unique': 'True', 'null': 'True'}),
171
            'machine': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'nics'", 'to': "orm['db.VirtualMachine']"}),
172
            'name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}),
173
            'network': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'nics'", 'to': "orm['db.Network']"}),
174
            'security_groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['db.SecurityGroup']", 'null': 'True', 'symmetrical': 'False'}),
175
            'state': ('django.db.models.fields.CharField', [], {'default': "'ACTIVE'", 'max_length': '32'}),
176
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
177
            'userid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'db_index': 'True'})
178
        },
179
        'db.quotaholderserial': {
180
            'Meta': {'ordering': "['serial']", 'object_name': 'QuotaHolderSerial'},
181
            'accept': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
182
            'pending': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
183
            'resolved': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
184
            'serial': ('django.db.models.fields.BigIntegerField', [], {'primary_key': 'True', 'db_index': 'True'})
185
        },
186
        'db.securitygroup': {
187
            'Meta': {'object_name': 'SecurityGroup'},
188
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
189
            'name': ('django.db.models.fields.CharField', [], {'max_length': '128'})
190
        },
191
        'db.subnet': {
192
            'Meta': {'object_name': 'Subnet'},
193
            'cidr': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
194
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
195
            'dhcp': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
196
            'dns_nameservers': ('synnefo.db.fields.SeparatedValuesField', [], {'null': 'True'}),
197
            'gateway': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
198
            'host_routes': ('synnefo.db.fields.SeparatedValuesField', [], {'null': 'True'}),
199
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
200
            'ipversion': ('django.db.models.fields.IntegerField', [], {'default': '4'}),
201
            'name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}),
202
            'network': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'subnets'", 'to': "orm['db.Network']"})
203
        },
204
        'db.virtualmachine': {
205
            'Meta': {'object_name': 'VirtualMachine'},
206
            'action': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '30', 'null': 'True'}),
207
            'backend': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'virtual_machines'", 'null': 'True', 'on_delete': 'models.PROTECT', 'to': "orm['db.Backend']"}),
208
            'backend_hash': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}),
209
            'backendjobid': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
210
            'backendjobstatus': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
211
            'backendlogmsg': ('django.db.models.fields.TextField', [], {'null': 'True'}),
212
            'backendopcode': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
213
            'backendtime': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(1, 1, 1, 0, 0)'}),
214
            'buildpercentage': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
215
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
216
            'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
217
            'flavor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['db.Flavor']", 'on_delete': 'models.PROTECT'}),
218
            'hostid': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
219
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
220
            'imageid': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
221
            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
222
            'operstate': ('django.db.models.fields.CharField', [], {'default': "'BUILD'", 'max_length': '30'}),
223
            'serial': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'virtual_machine'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['db.QuotaHolderSerial']"}),
224
            'suspended': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
225
            'task': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
226
            'task_job_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
227
            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
228
            'userid': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_index': 'True'})
229
        },
230
        'db.virtualmachinediagnostic': {
231
            'Meta': {'ordering': "['-created']", 'object_name': 'VirtualMachineDiagnostic'},
232
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
233
            'details': ('django.db.models.fields.TextField', [], {'null': 'True'}),
234
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
235
            'level': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
236
            'machine': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'diagnostics'", 'to': "orm['db.VirtualMachine']"}),
237
            'message': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
238
            'source': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
239
            'source_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'})
240
        },
241
        'db.virtualmachinemetadata': {
242
            'Meta': {'unique_together': "(('meta_key', 'vm'),)", 'object_name': 'VirtualMachineMetadata'},
243
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
244
            'meta_key': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
245
            'meta_value': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
246
            'vm': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'metadata'", 'to': "orm['db.VirtualMachine']"})
247
        }
248
    }
249

  
250
    complete_apps = ['db']
251
    symmetrical = True

Also available in: Unified diff