Revision 2509ce17 snf-cyclades-app/synnefo/api/servers.py

b/snf-cyclades-app/synnefo/api/servers.py
249 249
# access (SELECT..FOR UPDATE). Running create_server with commit_on_success
250 250
# would result in backends and public networks to be locked until the job is
251 251
# sent to the Ganeti backend.
252
@quotas.uses_commission
253 252
@transaction.commit_manually
254
def create_server(serials, request):
253
def create_server(request):
255 254
    # Normal Response Code: 202
256 255
    # Error Response Codes: computeFault (400, 500),
257 256
    #                       serviceUnavailable (503),
......
311 310
        flavor.disk_provider = None
312 311

  
313 312
    try:
314
        # Issue commission
315
        serial = quotas.issue_vm_commission(user_id, flavor)
316
        serials.append(serial)
317
        # Make the commission accepted, since in the end of this
318
        # transaction the VM will have been created in the DB.
319
        serial.accepted = True
320
        serial.save()
321

  
322 313
        # Allocate IP from public network
323 314
        (network, address) = util.get_public_ip(backend)
324 315
        nic = {'ip': address, 'network': network.backend_id}
......
331 322
            userid=user_id,
332 323
            imageid=image_id,
333 324
            flavor=flavor,
334
            action="CREATE",
335
            serial=serial)
325
            action="CREATE")
336 326

  
337 327
        # Create VM's public NIC. Do not wait notification form ganeti hooks to
338 328
        # create this NIC, because if the hooks never run (e.g. building error)
......
357 347
                meta_key=key,
358 348
                meta_value=val,
359 349
                vm=vm)
350
        # Issue commission to Quotaholder and accept it since at the end of
351
        # this transaction the Network object will be created in the DB.
352
        # Note: the following call does a commit!
353
        quotas.issue_and_accept_commission(vm)
360 354
    except:
361 355
        transaction.rollback()
362 356
        raise

Also available in: Unified diff