Revision 2e0916f2 snf-cyclades-app/synnefo/neutron/subnet_views.py

b/snf-cyclades-app/synnefo/neutron/subnet_views.py
162 162
    raise api.faults.BadRequest("Deletion of a subnet is not supported")
163 163

  
164 164

  
165

  
165 166
@api.api_method(http_method='PUT', user_required=True, logger=log)
166 167
def update_subnet(request, sub_id):
167 168
    '''Update info of a subnet'''
168 169

  
169 170

  
171
# util functions
172

  
173

  
170 174
def subnet_to_dict(subnet):
171 175
    '''Returns a dictionary containing the info of a subnet'''
172 176
    # FIX ME, allocation pools
......
184 188
    if network.subnet_set.filter(ipversion=version):
185 189
        raise api.faults.BadRequest("Only one subnet of IPv4/IPv6 per "
186 190
                                    "network is allowed")
191

  
192
def get_subnet_fromdb(subnet_id, user_id, for_update=False):
193
    """
194
    Return a Subnet instance or raise ItemNotFound.
195
    This is the same as util.get_network
196
    """
197
    try:
198
        subnet_id = int(subnet_id)
199
        objects = Subnet.objects
200
        if for_update:
201
            objects = objects.select_for_update()
202
        return objects.get(userid=user_id, id=subnet_id)
203
    except (ValueError, Subnet.DoesNotExist):
204
        raise api.faults.ItemNotFound('Network not found.')
205

  

Also available in: Unified diff