Esempio n. 1
0
 def test_server_invalid_state(self):
     """Check touch_to_state won't put a server into "BAD" state.
     """
     artifact_id = self.my_create_appliance("testbad")
     #But which exception?  Currently we get a TypeError
     with self.assertRaises(Exception):
         s.touch_to_state(None, artifact_id, "BAD")
Esempio n. 2
0
 def test_preboost_server(self):
     """Check touch_to_state puts a server into "Preparing" state.
     """
     artifact_id = self.my_create_appliance("testpreboost")
     s.touch_to_state(None, artifact_id, "Preparing")
     status = s.check_state(artifact_id)
     self.assertEqual(status, "Preparing")
Esempio n. 3
0
 def test_stop_server(self):
     """Check touch_to_state puts a server into "Stopped" state.
     """
     artifact_id = self.my_create_appliance("teststopped")
     s.touch_to_state(None, artifact_id, "Stopped")
     status = s.check_state(artifact_id)
     self.assertEqual(status, "Stopped")
Esempio n. 4
0
def deboost_server(request):
    """Deboost a server: ie:
        Credit the users account
        Cancel any scheduled De-Boost
        Set the CPUs and RAM to the previous state
        Put the server in a "Pre_Deboosting" status

    Note that a user can Deboost at ANY time, but they only get credit if credit is due.
    Deboosting a non-boosted server just amounts to a restart.

    :param {vm or name}: ID of VApp which we want to deboost.
    :returns: dict(touch_id, vm_id, credit) where credit is the refunded amount
    """
    vm_id, actor_id = _resolve_vm(request)

    credit = server.get_time_until_deboost(vm_id)[3]
    server.touch_to_add_credit(actor_id, credit)

    #Scheduled timeouts don't need cancelling as they are ignored on unboosted servers,
    #and if the user re-boosts then the new timeout will mask the old one.

    #Previous semantics would return the VM to the previous state, but this is not
    #what I really want - altering the baseline in the config should lead to all VMs
    #ending up in the new state after a Boost/Deboost.
    new_cores, new_ram = server.get_baseline_specification(vm_id)

    server.touch_to_add_specification(vm_id, new_cores, new_ram)

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

    return dict(touch_id=touch_id, vm_id=vm_id, credit=credit)
Esempio n. 5
0
def _set_server_state(request, target_state):
    """Basic function for putting a server into some state, for basic state-change calls."""
    vm_id, actor_id = _resolve_vm(request)
    return {
        "vm_id": vm_id,
        "touch_id": server.touch_to_state(actor_id, vm_id, target_state)
    }
Esempio n. 6
0
def deboost_server(request):
    """Deboost a server: ie:
        Credit the users account
        Cancel any scheduled De-Boost
        Set the CPUs and RAM to the previous state
        Put the server in a "Pre_Deboosting" status

    Note that a user can Deboost at ANY time, but they only get credit if credit is due.
    Deboosting a non-boosted server just amounts to a restart.

    :param {vm or name}: ID of VApp which we want to deboost.
    :returns: ???
    """
    vm_id, actor_id = _resolve_vm(request)

    credit = server.get_time_until_deboost(vm_id)[3]
    server.touch_to_add_credit(actor_id, credit)

    #Scheduled timeouts don't need cancelling as they are ignored on unboosted servers.

    #FIXME - yet more hard-coding for cores/RAM
    prev_cores = 1
    prev_ram = 16
    try:
        prev_cores, prev_ram = server.get_previous_specification(vm_id)
    except:
        #OK, use the defaults.
        pass

    #If we're not careful, with this "go back to previous config" semantics, if a user de-boosts
    #a server twice they will actually end up setting their baseline config to the boosted specs.
    #Therefore do a check.
    current_cores, current_ram = server.get_latest_specification(vm_id)

    if not (prev_ram > current_ram):
        server.touch_to_add_specification(vm_id, prev_cores, prev_ram)

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

    return dict(touch_id=touch_id, vm_id=vm_id, credit=credit)
Esempio n. 7
0
def deboost_server(request):
    """Deboost a server: ie:
        Credit the users account
        Cancel any scheduled De-Boost
        Set the CPUs and RAM to the previous state
        Put the server in a "Pre_Deboosting" status

    Note that a user can Deboost at ANY time, but they only get credit if credit is due.
    Deboosting a non-boosted server just amounts to a restart.

    :param {vm or name}: ID of VApp which we want to deboost.
    :returns: ???
    """
    vm_id, actor_id = _resolve_vm(request)

    credit = server.get_time_until_deboost(vm_id)[3]
    server.touch_to_add_credit(actor_id, credit)

    # Scheduled timeouts don't need cancelling as they are ignored on unboosted servers.

    # FIXME - yet more hard-coding for cores/RAM
    prev_cores = 1
    prev_ram = 16
    try:
        prev_cores, prev_ram = server.get_previous_specification(vm_id)
    except:
        # OK, use the defaults.
        pass

    # If we're not careful, with this "go back to previous config" semantics, if a user de-boosts
    # a server twice they will actually end up setting their baseline config to the boosted specs.
    # Therefore do a check.
    current_cores, current_ram = server.get_latest_specification(vm_id)

    if not (prev_ram > current_ram):
        server.touch_to_add_specification(vm_id, prev_cores, prev_ram)

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

    return dict(touch_id=touch_id, vm_id=vm_id, credit=credit)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
0
def _set_server_state(request, target_state):
    """Basic function for putting a server into some state, for basic state-change calls."""
    vm_id, actor_id = _resolve_vm(request)
    return {"vm_id": vm_id, "touch_id": server.touch_to_state(actor_id, vm_id, target_state)}