Revision 4e3789fd

b/snf-cyclades-app/synnefo/api/networks.py
1
# Copyright 2011-2013 GRNET S.A. All rights reserved.
1
# Copyright 2011-2014 GRNET S.A. All rights reserved.
2 2
#
3 3
# Redistribution and use in source and binary forms, with or
4 4
# without modification, are permitted provided that the following
......
107 107
    user_networks = Network.objects.filter(Q(userid=request.user_uniq) |
108 108
                                           Q(public=True))\
109 109
                                   .order_by('id')
110
    if detail:
111
        user_networks = user_networks.prefetch_related("subnets")
112 110

  
113 111
    user_networks = api.utils.filter_modified_since(request,
114 112
                                                    objects=user_networks)
......
193 191
    d = {'id': str(network.id), 'name': network.name}
194 192
    d['links'] = util.network_to_links(network.id)
195 193
    if detail:
196
        # Loop over subnets. Do not perform any extra query because of prefetch
197
        # related!
198
        subnet_ids = []
199
        for subnet in network.subnets.all():
200
            subnet_ids.append(subnet.id)
201

  
202 194
        state = "SNF:DRAINED" if network.drained else network.state
203 195
        d['user_id'] = network.userid
204 196
        d['tenant_id'] = network.project
......
209 201
        d['public'] = network.public
210 202
        d['router:external'] = network.external_router
211 203
        d['admin_state_up'] = True
212
        d['subnets'] = subnet_ids
204
        d['subnets'] = network.subnet_ids
213 205
        d['SNF:floating_ip_pool'] = network.floating_ip_pool
214 206
        d['deleted'] = network.deleted
215 207
    return d
......
219 211
def reassign_network(request, network, args):
220 212
    project = args.get("project")
221 213
    if project is None:
222
        raise faults.BadRequest("Missing 'project' attribute.")
214
        raise api.faults.BadRequest("Missing 'project' attribute.")
223 215
    networks.reassign(network, project)
224 216
    return HttpResponse(status=200)
225 217

  
b/snf-cyclades-app/synnefo/db/migrations/0101_auto__add_field_network_subnet_ids.py
1
# -*- coding: utf-8 -*-
2
import datetime
3
from south.db import db
4
from south.v2 import SchemaMigration
5
from django.db import models
6

  
7

  
8
class Migration(SchemaMigration):
9

  
10
    def forwards(self, orm):
11
        # Adding field 'Network.subnet_ids'
12
        db.add_column('db_network', 'subnet_ids',
13
                      self.gf('synnefo.db.fields.SeparatedValuesField')(null=True),
14
                      keep_default=False)
15

  
16

  
17
    def backwards(self, orm):
18
        # Deleting field 'Network.subnet_ids'
19
        db.delete_column('db_network', 'subnet_ids')
20

  
21

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

  
240
    complete_apps = ['db']
b/snf-cyclades-app/synnefo/db/migrations/0102_subnets_to_network.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
        n_subs = {}
12
        for (subnet_id, network_id) in orm.Subnet.objects.values_list("id", "network_id"):
13
            subnet_ids = n_subs.setdefault(network_id, [])
14
            subnet_ids.append(network_id)
15
        for network_id, subnet_ids in n_subs.items():
16
            updated = orm.Network.objects.filter(id=network_id).update(subnet_ids=subnet_ids)
17
            assert(updated == 1)
18
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
19

  
20
    def backwards(self, orm):
21
        "Write your backwards methods here."
22

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

  
241
    complete_apps = ['db']
242
    symmetrical = True
b/snf-cyclades-app/synnefo/db/models.py
506 506
    external_router = models.BooleanField(default=False)
507 507
    serial = models.ForeignKey(QuotaHolderSerial, related_name='network',
508 508
                               null=True, on_delete=models.SET_NULL)
509
    subnet_ids = fields.SeparatedValuesField("Subnet IDs", null=True)
509 510

  
510 511
    def __unicode__(self):
511 512
        return "<Network: %s>" % str(self.id)
b/snf-cyclades-app/synnefo/logic/subnets.py
83 83

  
84 84
    """
85 85
    try:
86
        network = Network.objects.get(id=network_id)
86
        network = Network.objects.select_for_update().get(id=network_id)
87 87
    except Network.DoesNotExist:
88 88
        raise api.faults.ItemNotFound("No network found with that id")
89 89

  
......
121 121
                                dhcp=dhcp, host_routes=host_routes,
122 122
                                dns_nameservers=dns_nameservers)
123 123

  
124
    network.subnet_ids.append(sub.id)
125
    network.save()
126

  
124 127
    gateway_ip = ipaddr.IPAddress(gateway) if gateway else None
125 128

  
126 129
    if allocation_pools is not None:

Also available in: Unified diff