Revision 40d53b77 snf-cyclades-app/synnefo/api/servers.py

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)

Also available in: Unified diff