Revision bdedfd9d

b/snf-cyclades-app/synnefo/api/subnets.py
80 80
def list_subnets(request, detail=True):
81 81
    """List all subnets of a user"""
82 82
    userid = request.user_uniq
83
    subnets_list = Subnet.objects.filter(Q(network__public=True) |
84
                                         (Q(network__userid=userid) &
85
                                          Q(network__public=False)))\
83
    subnets_list = Subnet.objects.filter(Q(public=True) |
84
                                         (Q(userid=userid) &
85
                                          Q(public=False)))\
86 86
                                 .order_by("id")
87
    subnets_list = subnets_list.prefetch_related("ip_pools")\
88
                               .select_related("network")
87
    subnets_list = subnets_list.prefetch_related("ip_pools")
89 88
    subnets_list = api.utils.filter_modified_since(request,
90 89
                                                   objects=subnets_list)
91 90

  
......
215 214
    allocation_pools = [render_ip_pool(pool)
216 215
                        for pool in subnet.ip_pools.all()]
217 216

  
218
    network = subnet.network
219 217
    d = {'id': str(subnet.id),
220 218
         'network_id': str(subnet.network_id),
221 219
         'name': subnet.name if subnet.name is not None else "",
222
         'tenant_id': network.userid,
223
         'user_id': network.userid,
220
         'tenant_id': subnet.userid,
221
         'user_id': subnet.userid,
222
         'public': subnet.public,
224 223
         'gateway_ip': subnet.gateway,
225 224
         'ip_version': subnet.ipversion,
226 225
         'cidr': subnet.cidr,
b/snf-cyclades-app/synnefo/db/migrations/0096_auto__add_field_subnet_userid__add_field_subnet_public.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 'Subnet.userid'
12
        db.add_column('db_subnet', 'userid',
13
                      self.gf('django.db.models.fields.CharField')(max_length=128, null=True, db_index=True),
14
                      keep_default=False)
15

  
16
        # Adding field 'Subnet.public'
17
        db.add_column('db_subnet', 'public',
18
                      self.gf('django.db.models.fields.BooleanField')(default=False, db_index=True),
19
                      keep_default=False)
20

  
21

  
22
    def backwards(self, orm):
23
        # Deleting field 'Subnet.userid'
24
        db.delete_column('db_subnet', 'userid')
25

  
26
        # Deleting field 'Subnet.public'
27
        db.delete_column('db_subnet', 'public')
28

  
29

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

  
243
    complete_apps = ['db']
b/snf-cyclades-app/synnefo/db/migrations/0097_userid_to_subnets.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 network in orm.Network.objects.all():
13
            network.subnets.update(userid=network.userid,
14
                                   public=network.public)
15

  
16
    def backwards(self, orm):
17
        "Write your backwards methods here."
18
        pass
19

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

  
233
    complete_apps = ['db']
234
    symmetrical = True
b/snf-cyclades-app/synnefo/db/models.py
609 609
class Subnet(models.Model):
610 610
    SUBNET_NAME_LENGTH = 128
611 611

  
612
    userid = models.CharField('User ID of the owner', max_length=128,
613
                              null=True, db_index=True)
614
    public = models.BooleanField(default=False, db_index=True)
615

  
612 616
    network = models.ForeignKey('Network', null=False, db_index=True,
613 617
                                related_name="subnets",
614 618
                                on_delete=models.PROTECT)
b/snf-cyclades-app/synnefo/db/models_factory.py
199 199
    dhcp = True
200 200
    dns_nameservers = []
201 201
    host_routes = []
202
    userid = factory.LazyAttribute(lambda self: self.network.userid)
203
    public = factory.LazyAttribute(lambda self: self.network.public)
202 204

  
203 205

  
204 206
class IPv4SubnetFactory(SubnetFactory):
b/snf-cyclades-app/synnefo/logic/subnets.py
117 117
                                   "name is too long")
118 118
    sub = Subnet.objects.create(name=name, network=network, cidr=cidr,
119 119
                                ipversion=ipversion, gateway=gateway,
120
                                userid=network.userid, public=network.public,
120 121
                                dhcp=dhcp, host_routes=host_routes,
121 122
                                dns_nameservers=dns_nameservers)
122 123

  
......
155 156
    try:
156 157
        objects = Subnet.objects
157 158
        subnet_id = int(subnet_id)
158
        subnet = objects.get(id=subnet_id)
159
        if (subnet.network.userid != user_id) and (subnet.network.public is
160
                                                   False):
161
            raise api.faults.Unauthorized("You're not allowed to view this "
162
                                          "subnet")
163
        return subnet
159
        return objects.get(Q(userid=user_id) | Q(public=True),
160
                           id=subnet_id)
164 161
    except (ValueError, TypeError):
165 162
        raise faults.BadRequest("Invalid subnet ID '%s'" % subnet_id)
166 163
    except Subnet.DoesNotExist:

Also available in: Unified diff