Пример #1
0
    def get_allocation_dict(self):
        if not self.allocation:
            return {}
        # Don't move it up. Circular reference.
        from django.conf import settings
        from service.monitoring import get_delta, _get_allocation_result
        delta = get_delta(self, time_period=settings.FIXED_WINDOW)
        allocation_result = _get_allocation_result(self.identity)
        over_allocation, diff_amount = allocation_result.total_difference()
        burn_time = allocation_result.get_burn_rate()
        # Moving from seconds to hours
        hourly_credit = int(allocation_result
                            .total_credit().total_seconds() / 3600.0)
        hourly_runtime = int(allocation_result
                             .total_runtime().total_seconds() / 3600.0)
        hourly_difference = int(diff_amount.total_seconds() / 3600.0)
        zero_time = allocation_result.time_to_zero()

        allocation_dict = {
            "threshold": hourly_credit,
            "current": hourly_runtime,
            "delta": ceil(delta.total_seconds() / 60),
            "burn": hourly_difference,
            "ttz": zero_time,
        }
        return allocation_dict
Пример #2
0
    def get_allocation_dict(self):
        if not self.allocation:
            return {}
        # Don't move it up. Circular reference.
        from django.conf import settings
        from service.monitoring import get_delta, _get_allocation_result
        delta = get_delta(self, time_period=settings.FIXED_WINDOW)
        allocation_result = _get_allocation_result(self.identity)
        over_allocation, diff_amount = allocation_result.total_difference()
        burn_time = allocation_result.get_burn_rate()
        # Moving from seconds to hours
        hourly_credit = int(allocation_result
                            .total_credit().total_seconds() / 3600.0)
        hourly_runtime = int(allocation_result
                             .total_runtime().total_seconds() / 3600.0)
        hourly_difference = int(diff_amount.total_seconds() / 3600.0)
        zero_time = allocation_result.time_to_zero()

        allocation_dict = {
            "threshold": hourly_credit,
            "current": hourly_runtime,
            "delta": ceil(delta.total_seconds() / 60),
            "burn": hourly_difference,
            "ttz": zero_time,
        }
        return allocation_dict
Пример #3
0
 def get_total_hours(self):
     from service.monitoring import _get_allocation_result
     limit_instances = self.instance_set.all().values_list(
         'provider_alias', flat=True).distinct()
     result = _get_allocation_result(self, limit_instances=limit_instances)
     total_hours = result.total_runtime().total_seconds() / 3600.0
     hours = round(total_hours, 2)
     return hours
Пример #4
0
 def get_total_hours(self):
     from service.monitoring import _get_allocation_result
     identity = self.created_by_identity
     limit_instances = [self.provider_alias]
     result = _get_allocation_result(identity,
                                     limit_instances=limit_instances)
     total_hours = result.total_runtime().total_seconds() / 3600.0
     hours = round(total_hours, 2)
     return hours
Пример #5
0
 def total_usage(self, start_date, end_date):
     # Undoubtedly will cause circular dependencies
     from service.monitoring import _get_allocation_result
     allocation_result = _get_allocation_result(self, start_date, end_date)
     if not allocation_result:
         # Flag to the plugin you have an error in counting.
         return -1
     total_au = allocation_result.total_runtime().total_seconds() / 3600.0
     return total_au
Пример #6
0
 def total_usage(self, start_date, end_date):
     # Undoubtedly will cause circular dependencies
     from service.monitoring import _get_allocation_result
     allocation_result = _get_allocation_result(self, start_date, end_date)
     if not allocation_result:
         # Flag to the plugin you have an error in counting.
         return -1
     total_au = allocation_result.total_runtime().total_seconds() / 3600.0
     return total_au
Пример #7
0
 def get_total_hours(self):
     from service.monitoring import _get_allocation_result
     identity = self.created_by_identity
     limit_instances = [self.provider_alias]
     result = _get_allocation_result(
         identity,
         limit_instances=limit_instances)
     total_hours = result.total_runtime().total_seconds()/3600.0
     hours = round(total_hours, 2)
     return hours
Пример #8
0
 def get_total_hours(self):
     from service.monitoring import _get_allocation_result
     limit_instances = self.instance_set.all().values_list(
             'provider_alias', flat=True
         ).distinct()
     result = _get_allocation_result(
         self,
         limit_instances=limit_instances)
     total_hours = result.total_runtime().total_seconds()/3600.0
     hours = round(total_hours, 2)
     return hours
Пример #9
0
 def get_total_hours(self):
     from service.monitoring import _get_allocation_result
     identity = self.instance.created_by_identity
     history_list = self._base_manager.filter(id=self.id)
     limit_history = [hist.id for hist in history_list]
     limit_instances = [self.instance.provider_alias]
     result = _get_allocation_result(identity,
                                     limit_instances=limit_instances,
                                     limit_history=limit_history)
     total_hours = result.total_runtime().total_seconds() / 3600.0
     hours = round(total_hours, 2)
     return hours
Пример #10
0
 def get_total_hours(self):
     from service.monitoring import _get_allocation_result
     identity = self.instance.created_by_identity
     history_list = self.__class__.objects.filter(id=self.id)
     limit_history = [hist.id for hist in history_list]
     limit_instances = [self.instance.provider_alias]
     result = _get_allocation_result(
         identity,
         limit_instances=limit_instances,
         limit_history=limit_history)
     total_hours = result.total_runtime().total_seconds()/3600.0
     hours = round(total_hours, 2)
     return hours
def _get_results(idents):
    results = []
    total = len(idents)
    for idx,ident in enumerate(idents):
        try:
            result = _get_allocation_result(ident)
            results.append((ident, result))
        except Exception as exc:
            print "Error calculating for identity: %s" % ident
            print exc

        if total > 10 and idx % int(total / 10) == 0:
            print "Calculating %s/%s.." % (idx, total)
    return results
Пример #12
0
 def get_allocation_usage(self):
     # Undoubtedly will cause circular dependencies
     from service.monitoring import _get_allocation_result
     allocation_result = _get_allocation_result(self)
     over_allocation, diff_amount = allocation_result.total_difference()
     burn_time = allocation_result.get_burn_rate()
     # Moving from seconds to hours
     hourly_credit = int(allocation_result
                         .total_credit().total_seconds() / 3600.0)
     hourly_runtime = int(allocation_result
                          .total_runtime().total_seconds() / 3600.0)
     hourly_difference = int(diff_amount.total_seconds() / 3600.0)
     zero_time = allocation_result.time_to_zero()
     return {
         "threshold": hourly_credit,  # Total amount
         "current": hourly_runtime,  # Total used
         "remaining": hourly_difference,
         "ttz": zero_time,  # Time Til Zero
     }
Пример #13
0
 def get_allocation_usage(self):
     # Undoubtedly will cause circular dependencies
     from service.monitoring import _get_allocation_result
     allocation_result = _get_allocation_result(self)
     over_allocation, diff_amount = allocation_result.total_difference()
     burn_time = allocation_result.get_burn_rate()
     # Moving from seconds to hours
     hourly_credit = int(allocation_result
                         .total_credit().total_seconds() / 3600.0)
     hourly_runtime = int(allocation_result
                          .total_runtime().total_seconds() / 3600.0)
     hourly_difference = int(diff_amount.total_seconds() / 3600.0)
     zero_time = allocation_result.time_to_zero()
     return {
         "threshold": hourly_credit,  # Total amount
         "current": hourly_runtime,  # Total used
         "remaining": hourly_difference,
         "ttz": zero_time,  # Time Til Zero
     }