Example #1
0
def _create_monthly_window_input(identity, core_allocation, 
        start_date, end_date, interval_delta=None):
    """
    This function is meant to create an allocation input that
    is identical in functionality to that of the ORIGINAL allocation system.
    """

    if not end_date:
        end_date = timezone.now()

    if not start_date:
        delta_time = get_delta(core_allocation, settings.FIXED_WINDOW, end_date)
        start_date = end_date - delta_time
    else:
        delta_time = end_date - start_date
    #TODO: I wanted delta_time.. why?
    #Guaranteed a range (IF BOTH are NONE: Starting @ FIXED_WINDOW until NOW)
    if core_allocation:
        initial_recharge = AllocationRecharge(
                name="%s Assigned allocation" % identity.created_by.username,
                unit=TimeUnit.minute, amount=core_allocation.threshold,
                recharge_date=start_date)
    else:
        initial_recharge = AllocationUnlimited(start_date)
    #Retrieve the core that could have an impact..
    core_instances = _core_instances_for(identity, start_date)



    #Noteably MISSING: 'active', 'running'
    multiply_by_cpu = MultiplySizeCPU(name="Multiply TimeUsed by CPU", multiplier=1)
    ignore_inactive = IgnoreStatusRule("Ignore Inactive StatusHistory", value=["build", "pending",
        "hard_reboot", "reboot",
         "migrating", "rescue",
         "resize", "verify_resize",
        "shutoff", "shutting-down",
        "suspended", "terminated",
        "deleted", "error", "unknown","N/A",
        ])
    #Convert Core Models --> Allocation/core Models
    alloc_instances = [AllocInstance.from_core(inst, start_date)
                       for inst in core_instances]
    return Allocation(
            credits=[initial_recharge],
            rules=[multiply_by_cpu, ignore_inactive], instances=alloc_instances,
            start_date=start_date, end_date=end_date,
            interval_delta=interval_delta)
Example #2
0
AVAILABLE_SIZES = {
    "test.tiny": tiny_size,
    "test.small": small_size,
    "test.medium": medium_size,
    "test.large": large_size
}

STATUS_CHOICES = frozenset(["active", "suspended", "build", "resize"])

# Rules
carry_forward = CarryForwardTime()

multiply_by_ram = MultiplySizeRAM(name="Multiply TimeUsed by Ram (*1GB)",
                                  multiplier=(1 / 1024))
multiply_by_cpu = MultiplySizeCPU(name="Multiply TimeUsed by CPU",
                                  multiplier=1)
multiply_by_disk = MultiplySizeDisk(name="Multiply TimeUsed by Disk",
                                    multiplier=1)

half_usage_by_ram = MultiplySizeRAM(
    name="Multiply TimeUsed by 50% of Ram (GB)", multiplier=.5 * (1 / 1024))
half_usage_by_cpu = MultiplySizeCPU(name="Multiply TimeUsed by 50% of CPU",
                                    multiplier=.5)
half_usage_by_disk = MultiplySizeDisk(name="Multiply TimeUsed by 50% of Disk",
                                      multiplier=.5)

zero_burn_rate = MultiplyBurnTime(name="Stop all Total Time Used",
                                  multiplier=0.0)
half_burn_rate = MultiplyBurnTime(name="Half-Off Total Time Used",
                                  multiplier=0.5)
double_burn_rate = MultiplyBurnTime(name="Double Total Time Used",
Example #3
0
 def __init__(self, rules=[]):
     multiply_by_cpu = MultiplySizeCPU(name="Multiply TimeUsed by CPU",
                                       multiplier=1)
     super(MultiplySizeCPURule, self).__init__([multiply_by_cpu])