Revision 40d53b77

b/snf-cyclades-app/synnefo/api/servers.py
322 322
@transaction.commit_manually
323 323
def do_create_server(userid, name, password, flavor, image, metadata={},
324 324
                     personality=[], network=None, backend=None):
325
    if backend is None:
326
        # Allocate backend to host the server. Commit after allocation to
327
        # release the locks hold by the backend allocator.
328
        try:
329
            backend_allocator = BackendAllocator()
330
            backend = backend_allocator.allocate(userid, flavor)
331
            if backend is None:
332
                log.error("No available backend for VM with flavor %s", flavor)
333
                raise faults.ServiceUnavailable("No available backends")
334
        except:
335
            transaction.rollback()
336
            raise
337
        else:
338
            transaction.commit()
339

  
340 325
    # Fix flavor for archipelago
341 326
    disk_template, provider = util.get_flavor_provider(flavor)
342 327
    if provider:
......
349 334
        flavor.disk_origin = None
350 335

  
351 336
    try:
337
        if backend is None:
338
            # Allocate backend to host the server.
339
            backend_allocator = BackendAllocator()
340
            backend = backend_allocator.allocate(userid, flavor)
341
            if backend is None:
342
                log.error("No available backend for VM with flavor %s", flavor)
343
                raise faults.ServiceUnavailable("No available backends")
344

  
352 345
        if network is None:
353 346
            # Allocate IP from public network
354 347
            (network, address) = util.get_public_ip(backend)
b/snf-cyclades-app/synnefo/logic/backend.py
97 97
        #
98 98
        if status == 'success' or (status == 'error' and
99 99
                                   vm.operstate == 'ERROR'):
100
            release_instance_nics(vm)
101
            vm.nics.all().delete()
100
            _process_net_status(vm, etime, nics=[])
102 101
            vm.deleted = True
103 102
            vm.operstate = state_for_success
104 103
            vm.backendtime = etime
......
133 132
    ganeti_nics = process_ganeti_nics(nics)
134 133
    if not nics_changed(vm.nics.order_by('index'), ganeti_nics):
135 134
        log.debug("NICs for VM %s have not changed", vm)
135
        return
136

  
137
    # Get X-Lock on backend before getting X-Lock on network IP pools, to
138
    # guarantee that no deadlock will occur with Backend allocator.
139
    Backend.objects.select_for_update().get(id=vm.backend_id)
136 140

  
137 141
    release_instance_nics(vm)
138 142

  

Also available in: Unified diff