Revision 95a213d4

b/snf-cyclades-app/synnefo/api/networks.py
23 23

  
24 24
urlpatterns = patterns(
25 25
    'synnefo.api.networks',
26
     (r'^(?:/|.json|.xml)?$', 'demux'),
27
     (r'^/(\w+)(?:/|.json|.xml)?$', 'network_demux'))
26
    (r'^(?:/|.json|.xml)?$', 'demux'),
27
    (r'^/(\w+)(?:/|.json|.xml)?$', 'network_demux'))
28

  
28 29

  
29 30
def demux(request):
30 31
    if request.method == 'GET':
......
88 89
        try:
89 90
            flavor = d['type']
90 91
        except KeyError:
91
            raise faults.BadRequest("Missing request parameter 'type'")
92
            raise api.faults.BadRequest("Missing request parameter 'type'")
92 93

  
93 94
        if flavor not in Network.FLAVORS.keys():
94 95
            raise api.faults.BadRequest("Invalid network type '%s'"
b/snf-cyclades-app/synnefo/api/util.py
206 206
        disk_template, provider = disk_template.split("_", 1)
207 207
    return disk_template, provider
208 208

  
209
'''
209

  
210 210
def get_network(network_id, user_id, for_update=False, non_deleted=False):
211 211
    """Return a Network instance or raise ItemNotFound."""
212 212

  
......
222 222
        return network
223 223
    except (ValueError, Network.DoesNotExist):
224 224
        raise faults.ItemNotFound('Network not found.')
225
'''
226
def get_network(network_id, user_id, public=False, for_update=False):
225

  
226

  
227
def get_port(port_id, user_id, for_update=False):
227 228
    """
228
    Return a Network instance or raise ItemNotFound.
229
    Return a NetworkInteface instance or raise ItemNotFound.
229 230
    """
230 231
    try:
231
        objects = Network.objects
232
        if for_update:
233
            objects = objects.select_for_update()
234
        if public:
235
            objects = objects.filter(public=True)
236
        return objects.get(Q(userid=user_id) | Q(public=True), id=network_id)
237
    except (ValueError, Network.DoesNotExist):
238
        raise faults.ItemNotFound('Network not found.')
239

  
240
def get_port(port_id, user_id, for_update=False):
241
     """
242
     Return a NetworkInteface instance or raise ItemNotFound.
243
     """
244
     try:
245 232
        objects = NetworkInterface.objects
246 233
        if for_update:
247 234
            objects = objects.select_for_update()
......
249 236
        port = objects.get(network__userid=user_id, id=port_id)
250 237

  
251 238
        if (port.device_owner != "vm") and for_update:
252
            raise api.faults.BadRequest('Can not update non vm port')
239
            raise faults.BadRequest('Can not update non vm port')
253 240

  
254 241
        return port
255
     except (ValueError, NetworkInterface.DoesNotExist):
256
         raise faults.ItemNotFound('Port not found.')
242
    except (ValueError, NetworkInterface.DoesNotExist):
243
        raise faults.ItemNotFound('Port not found.')
244

  
257 245

  
258 246
def get_floating_ip(user_id, ipv4, for_update=False):
259 247
    try:

Also available in: Unified diff