def get_burn_time(user, identity_id, delta, threshold): """ INPUT: Total time allowed, total time used (so far), The CPU cores multiplier """ #DONT MOVE -- Circ.Dep. from service.instance import get_core_instances if type(user) is not User: user = User.objects.filter(username=user) if type(delta) is not timedelta: delta = timedelta(minutes=delta) if type(threshold) is not timedelta: delta = timedelta(minutes=threshold) time_used = get_time(user, identity_id, delta) time_remaining = threshold - time_used #If we used all of our allocation, dont calculate burn time if time_remaining < timedelta(0): return None instances = get_core_instances(identity_id) #If we have no instances, burn-time does not apply if not instances: return None cpu_cores = sum([inst.esh.size.cpu for inst in instances if inst.last_history() and inst.last_history().is_active()]) #If we have no active cores, burn-time does not apply if cpu_cores == 0: return None #Calculate burn time by dividing remaining time over running cores burn_time = time_remaining/cpu_cores return burn_time
def get_burn_time(user, identity_id, delta, threshold): """ INPUT: Total time allowed, total time used (so far), The CPU cores multiplier """ #DONT MOVE -- Circ.Dep. from service.instance import get_core_instances if type(user) is not User: user = User.objects.filter(username=user) if type(delta) is not timedelta: delta = timedelta(minutes=delta) if type(threshold) is not timedelta: delta = timedelta(minutes=threshold) time_used = get_time(user, identity_id, delta) time_remaining = threshold - time_used #If we used all of our allocation, dont calculate burn time if time_remaining < timedelta(0): return None instances = get_core_instances(identity_id) #If we have no instances, burn-time does not apply if not instances: return None cpu_cores = sum([ inst.esh.size.cpu for inst in instances if inst.last_history() and inst.last_history().is_active() ]) #If we have no active cores, burn-time does not apply if cpu_cores == 0: return None #Calculate burn time by dividing remaining time over running cores burn_time = time_remaining / cpu_cores return burn_time
def get_burn_time(user, identity_id, delta, threshold, now_time=None): """ INPUT: Total time allowed, total time used (so far), OUTPUT: delta representing time remaining (from now) """ #DONT MOVE -- Circ.Dep. from service.instance import get_core_instances #Allow for multiple 'types' to be sent in if type(user) is not User: #not user, so this is a str with username user = User.objects.filter(username=user) if type(delta) is not timedelta: #not delta, so this is the int for minutes delta = timedelta(minutes=delta) if type(threshold) is not timedelta: #not delta, so this is the int for minutes delta = timedelta(minutes=threshold) #Assume we are burned out. burn_time = timedelta(0) #If we have no instances, burn-time does not apply instances = get_core_instances(identity_id) if not instances: return burn_time #Remaining time: What your allotted - What you used before now time_used, _ = core_instance_time(user, identity_id, delta, now_time=now_time) #delta = delta - delta time_remaining = threshold - time_used #If we used all of our allocation, we are burned out. if time_remaining < timedelta(0): return burn_time cpu_cores = get_cpu_count(user, identity_id) #If we have no active cores, burn-time does not apply if cpu_cores == 0: return burn_time #Calculate burn time by dividing remaining time over running cores #delta / int = delta (ex. 300 mins / 3 = 100 mins) burn_time = time_remaining / cpu_cores return burn_time
def get_burn_time(user, identity_id, delta, threshold, now_time=None): """ INPUT: Total time allowed, total time used (so far), OUTPUT: delta representing time remaining (from now) """ #DONT MOVE -- Circ.Dep. from service.instance import get_core_instances #Allow for multiple 'types' to be sent in if type(user) is not User: #not user, so this is a str with username user = User.objects.filter(username=user) if type(delta) is not timedelta: #not delta, so this is the int for minutes delta = timedelta(minutes=delta) if type(threshold) is not timedelta: #not delta, so this is the int for minutes delta = timedelta(minutes=threshold) #Assume we are burned out. burn_time = timedelta(0) #If we have no instances, burn-time does not apply instances = get_core_instances(identity_id) if not instances: return burn_time #Remaining time: What your allotted - What you used before now time_used, _ = core_instance_time( user, identity_id, delta, now_time=now_time) #delta = delta - delta time_remaining = threshold - time_used #If we used all of our allocation, we are burned out. if time_remaining < timedelta(0): return burn_time cpu_cores = get_cpu_count(user, identity_id) #If we have no active cores, burn-time does not apply if cpu_cores == 0: return burn_time #Calculate burn time by dividing remaining time over running cores #delta / int = delta (ex. 300 mins / 3 = 100 mins) burn_time = time_remaining/cpu_cores return burn_time