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)
def get_server_specification(request): """ Get the specification of a machine. Returns RAM in GB and number of cores in a JSON object.""" vm_id, actor_id = _resolve_vm(request) cores, ram = server.get_latest_specification(vm_id) return dict(cores=cores, ram=ram, artifact_id=vm_id)
def test_add_specification(self): """Add a specification to a machine and recall it.""" artifact_id = self.my_create_appliance("testspecification") s.touch_to_add_specification(artifact_id,2,4) cores, ram = s.get_latest_specification(artifact_id) self.assertEqual(cores, 2) self.assertEqual(ram, 4)
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)
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)
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)