Exemplo n.º 1
0
def extend_boost_on_server(request):
    """Extends the Boost period on a server by adding a new deboost timeout, if
       the user can afford it, and debiting the cost.
    """
    vm_id, actor_id = _resolve_vm(request)
    hours = int(request.POST['hours'])

    #See what level of boost we have just now.
    cores, ram = server.get_latest_specification(vm_id)

    cost = server.check_and_remove_credits(actor_id, ram, cores, hours)

    if not cost:
        #Either we can't afford it or we can't determine the cost.
        return HTTPBadRequest()

    #Work out when the new de-boost should be.  First get the remaining boost time as
    #hours.  It's unlikely to be a whole number.  If the boost has expired somehow then
    #don't be mean - count from now.
    remaining_time = (server.get_time_until_deboost(vm_id)[1] or 0) / 3600.0
    if remaining_time < 0: remaining_time = 0

    #Schedule a later de-boost
    server.touch_to_add_deboost(vm_id, hours + remaining_time)

    return dict(vm_id=vm_id, cost=cost)
Exemplo n.º 2
0
def extend_boost_on_server(request):
    """Extends the Boost period on a server by adding a new deboost timeout, if
       the user can afford it, and debiting the cost.
    """
    vm_id, actor_id = _resolve_vm(request)
    hours = int(request.POST["hours"])

    # See what level of boost we have just now.  Again, need to FIXME that hard-coding
    cores, ram = server.get_latest_specification(vm_id)

    cost = server.check_and_remove_credits(actor_id, ram, cores, hours)

    if not cost:
        # Either we can't afford it or we can't determine the cost.
        return HTTPBadRequest()

    # Work out when the new de-boost should be.  First get the remaining boost time as
    # hours.  It's unlikely to be a whole number.  If the boost has expired somehow then
    # don't be mean - count from now.
    remaining_time = (server.get_time_until_deboost(vm_id)[1] or 0) / 3600.0
    if remaining_time < 0:
        remaining_time = 0

    # Schedule a later de-boost
    server.touch_to_add_deboost(vm_id, hours + remaining_time)

    return dict(vm_id=vm_id, cost=cost)
Exemplo n.º 3
0
def boost_server(request):
    """Boost a server: ie:
        Debit the users account
        Schedule a De-Boost
        Set the CPUs and RAM
        Put the server in a "preparing" status

    :param {vm or name}: ID of VApp which we want to boost.
    :ram: ram wanted
    :cores: cores wanted
    :hours: hours of boost wanted
    :returns: JSON containing VApp ID and job ID for progress calls.
    """
    vm_id, actor_id = _resolve_vm(request)

    hours = int(request.POST['hours'])
    cores = int(request.POST['cores'])
    ram = int(request.POST['ram'])

    # FIXME: Really the user should boost to a named level, rather than directly
    # specifying RAM and cores.  For now I'm just going to work out the cost based
    # on the cores requested, and assume the RAM level matches it.
    cost = server.check_and_remove_credits(actor_id, ram, cores, hours)

    if not cost:
        #Either we can't afford it or we can't determine the cost.
        return HTTPBadRequest()

    #Schedule a de-boost
    server.touch_to_add_deboost(vm_id, hours)

    # Set spec
    server.touch_to_add_specification(vm_id, cores, ram)

    # Tell the agents to get to work.
    touch_id = server.touch_to_state(actor_id, vm_id, "Preparing")

    return dict(touch_id=touch_id, vm_id=vm_id, cost=cost)
Exemplo n.º 4
0
def boost_server(request):
    """Boost a server: ie:
        Debit the users account
        Schedule a De-Boost
        Set the CPUs and RAM
        Put the server in a "preparing" status

    :param {vm or name}: ID of VApp which we want to boost.
    :ram: ram wanted
    :cores: cores wanted
    :hours: hours of boost wanted
    :returns: JSON containing VApp ID and job ID for progress calls.
    """
    vm_id, actor_id = _resolve_vm(request)

    hours = int(request.POST["hours"])
    cores = int(request.POST["cores"])
    ram = int(request.POST["ram"])

    # FIXME: Really the user should boost to a named level, rather than directly
    # specifying RAM and cores.  For now I'm just going to work out the cost based
    # on the cores requested, and assume the RAM level matches it.
    cost = server.check_and_remove_credits(actor_id, ram, cores, hours)

    if not cost:
        # Either we can't afford it or we can't determine the cost.
        return HTTPBadRequest()

    # Schedule a de-boost
    server.touch_to_add_deboost(vm_id, hours)

    # Set spec
    server.touch_to_add_specification(vm_id, cores, ram)

    # Tell the agents to get to work.
    touch_id = server.touch_to_state(actor_id, vm_id, "Preparing")

    return dict(touch_id=touch_id, vm_id=vm_id, cost=cost)