コード例 #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.allocation import core_instance_time, get_burn_time,\
            delta_to_minutes, delta_to_hours, get_delta
        delta = get_delta(self, time_period=settings.FIXED_WINDOW)
        #Keeps the times on these calculations consistent!
        now_time = timezone.now()
        time_used, _ = core_instance_time(self.identity.created_by,
                                          self.identity.id,
                                          delta,
                                          now_time=now_time)
        hours_used = delta_to_hours(time_used)

        burn_time = get_burn_time(self.identity.created_by,
                                  self.identity.id,
                                  delta,
                                  timedelta(minutes=self.allocation.threshold),
                                  now_time=now_time)

        zero_time = now_time + burn_time if burn_time else None
        burned_per_hour = delta_to_hours(burn_time)

        allocation_dict = {
            "threshold": floor(self.allocation.threshold / 60),
            "current": hours_used,
            "delta": ceil(delta.total_seconds() / 60),
            "burn": burned_per_hour,
            "ttz": zero_time,
        }
        return allocation_dict
コード例 #2
0
ファイル: group.py プロジェクト: chromabinary/atmosphere
 def get_allocation_dict(self):
     if not self.allocation:
         return {}
     #Don't move it up. Circular reference.
     from service.allocation import core_instance_time, get_burn_time,\
         delta_to_minutes, delta_to_hours, get_delta
     delta = get_delta(self, time_period=relativedelta(day=1, months=1))
     time_used = core_instance_time(self.identity.created_by,
                          self.identity.id,
                          delta)
     burn_time = get_burn_time(self.identity.created_by, self.identity.id,
                               delta,
                               timedelta(minutes=self.allocation.threshold))
     mins_consumed = delta_to_minutes(time_used)
     if burn_time:
         burn_time = delta_to_hours(burn_time)
     zero_time = datetime.now() + timedelta(
             minutes=(self.allocation.threshold - mins_consumed))
     allocation_dict = {
         "threshold": floor(self.allocation.threshold/60),
         "current": floor(mins_consumed/60),
         "delta": ceil(delta.total_seconds()/60),
         "burn": burn_time,
         "ttz": zero_time,
     }
     return allocation_dict
コード例 #3
0
ファイル: group.py プロジェクト: 420reich/atmosphere
    def get_allocation_dict(self):
        if not self.allocation:
            return {}
        #Don't move it up. Circular reference.
        from django.conf import settings
        from service.allocation import core_instance_time, get_burn_time,\
            delta_to_minutes, delta_to_hours, get_delta
        delta = get_delta(self, time_period=settings.FIXED_WINDOW)
        #Keeps the times on these calculations consistent!
        now_time = timezone.now()
        time_used, _ = core_instance_time(self.identity.created_by,
                             self.identity.id,
                             delta,
                             now_time=now_time)
        hours_used = delta_to_hours(time_used)

        burn_time = get_burn_time(self.identity.created_by, self.identity.id,
                                  delta,
                                  timedelta(minutes=self.allocation.threshold),
                                  now_time=now_time)

        zero_time = now_time + burn_time if burn_time else None
        burned_per_hour = delta_to_hours(burn_time)

        allocation_dict = {
            "threshold": floor(self.allocation.threshold/60),
            "current": hours_used,
            "delta": ceil(delta.total_seconds()/60),
            "burn": burned_per_hour,
            "ttz": zero_time,
        }
        return allocation_dict
コード例 #4
0
def check_usernames(provider_id, usernames):
    for username in usernames:
        ident = Identity.objects.get(provider__id=provider_id, created_by__username=username)
        print "Provider: %s - Username: %s" % (ident.provider, ident.created_by.username)
        total_time, instances_map = core_instance_time(ident.created_by, ident.id, get_delta(get_allocation(ident.created_by.username, ident.id),settings.FIXED_WINDOW, timezone.now()), [], now_time=timezone.now())
        instance_list = instances_map.keys()
        for instance in instance_list:
            print "Instance:%s Time Used:%s" % (instance.provider_alias, instance.active_time)
            for history in instances_map[instance]:
                if history.cpu_time > timezone.timedelta(0):
                    print "Status:%s %s*(%s - %s) = %s" % ( history.status.name, history.size.cpu, history.start_date, history.end_date, history.cpu_time)
        print "Total Time Given:%s Total time used: %s" % (timezone.timedelta(minutes=get_allocation(ident.created_by.username, ident.id).threshold),total_time)