Example #1
0
def remove(request, net, args):
    # Normal Response Code: 202
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       badMediaType(415),
    #                       itemNotFound (404),
    #                       overLimit (413)

    try:  # attachment string: nic-<vm-id>-<nic-index>
        server_id = args.get('attachment', None).split('-')[1]
        nic_index = args.get('attachment', None).split('-')[2]
    except AttributeError:
        raise faults.BadRequest("Malformed Request")
    except IndexError:
        raise faults.BadRequest('Malformed Network Interface Id')

    if not server_id or not nic_index:
        raise faults.BadRequest('Malformed Request.')

    vm = get_vm(server_id, request.user_uniq, non_suspended=True)
    nic = get_nic_from_index(vm, nic_index)

    log.info("Removing NIC %s from VM %s", str(nic.index), vm)

    if nic.dirty:
        raise faults.BuildInProgress('Machine is busy.')
    else:
        vm.nics.all().update(dirty=True)

    backend.disconnect_from_network(vm, nic)
    return HttpResponse(status=202)
Example #2
0
def remove(request, net, args):
    # Normal Response Code: 202
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       badMediaType(415),
    #                       itemNotFound (404),
    #                       overLimit (413)

    try:  # attachment string: nic-<vm-id>-<nic-index>
        server_id = args.get('attachment', None).split('-')[1]
        nic_index = args.get('attachment', None).split('-')[2]
    except AttributeError:
        raise faults.BadRequest("Malformed Request")
    except IndexError:
        raise faults.BadRequest('Malformed Network Interface Id')

    if not server_id or not nic_index:
        raise faults.BadRequest('Malformed Request.')

    vm = get_vm(server_id, request.user_uniq, non_suspended=True)
    nic = get_nic_from_index(vm, nic_index)

    log.info("Removing NIC %s from VM %s", str(nic.index), vm)

    if nic.dirty:
        raise faults.BuildInProgress('Machine is busy.')
    else:
        vm.nics.all().update(dirty=True)

    backend.disconnect_from_network(vm, nic)
    return HttpResponse(status=202)
Example #3
0
def disconnect(vm, nic):
    log.info("Removing NIC %s from VM %s", nic, vm)
    return backend.disconnect_from_network(vm, nic)
Example #4
0
def disconnect(vm, nic):
    log.info("Removing NIC %s from VM %s", nic, vm)
    return backend.disconnect_from_network(vm, nic)
Example #5
0
def disconnect_port(vm, nic):
    with commands.ServerCommand("DISCONNECT", vm):
        log.info("Removing NIC %s from VM %s", nic, vm)
        job_id = backend.disconnect_from_network(vm, nic)
        vm.record_job(job_id)
        return vm
Example #6
0
def disconnect_port(vm, nic):
    with commands.ServerCommand("DISCONNECT", vm):
        log.info("Removing NIC %s from VM %s", nic, vm)
        job_id = backend.disconnect_from_network(vm, nic)
        vm.record_job(job_id)
        return vm