Revision 4e3789fd snf-cyclades-app/synnefo/api/networks.py
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 |
|
Also available in: Unified diff