Revision f46c95c4 snf-astakos-app/astakos/im/endpoints/quotaholder.py

b/snf-astakos-app/astakos/im/endpoints/quotaholder.py
57 57
        def wrapper(entities=(), client=None, **kwargs):
58 58
            if not entities:
59 59
                return ()
60
        
60

  
61 61
            if not QUOTA_HOLDER_URL:
62 62
                return ()
63
        
63

  
64 64
            c = client or QuotaholderHTTP(QUOTA_HOLDER_URL)
65 65
            func = c.__dict__.get(func_name)
66 66
            if not func:
67 67
                return c,
68
            
68

  
69 69
            data = payload_func(entities, client, **kwargs)
70 70
            if not data:
71 71
                return c,
72
            
72

  
73 73
            funcname = func.__name__
74 74
            kwargs = {'context': {}, funcname: data}
75 75
            rejected = func(**kwargs)
......
79 79
        return wrapper
80 80
    return decorator
81 81

  
82

  
82 83
@call('set_quota')
83 84
def send_quota(users, client=None):
84 85
    data = []
......
91 92
            import_limit = None
92 93
            export_limit = None
93 94
            flags = 0
94
            args = (user.email, resource, key, quantity, capacity, import_limit,
95
                    export_limit, flags)
95
            args = (
96
                user.email, resource, key, quantity, capacity, import_limit,
97
                export_limit, flags)
96 98
            append(args)
97 99
    return data
98 100

  
......
172 174

  
173 175
SECOND_RESOLUTION = 1
174 176

  
177

  
175 178
def total_seconds(timedelta_object):
176 179
    return timedelta_object.seconds + timedelta_object.days * 86400
177 180

  
181

  
178 182
def iter_timeline(timeline, before):
179 183
    if not timeline:
180 184
        return
......
186 190
    t['issue_time'] = before
187 191
    yield t
188 192

  
193

  
189 194
def _usage_units(timeline, after, before, details=0):
190 195

  
191 196
    t_total = 0
......
226 231
            'total',
227 232
            point['resource'],
228 233
            issue_time,
229
            uu_total/t_total,
234
            uu_total / t_total,
230 235
            uu_total)
231 236

  
237

  
232 238
def usage_units(timeline, after, before, details=0):
233 239
    return list(_usage_units(timeline, after, before, details=details))
234 240

  
241

  
235 242
def traffic_units(timeline, after, before, details=0):
236 243
    tu_total = 0
237 244
    target = None
......
263 270
            'total',
264 271
            point['resource'],
265 272
            issue_time,
266
            tu_total//len(timeline),
273
            tu_total // len(timeline),
267 274
            tu_total)
268 275

  
276

  
269 277
def timeline_charge(entity, resource, after, before, details, charge_type):
270 278
    key = '1'
271 279
    if charge_type == 'charge_usage':
......
278 286

  
279 287
    quotaholder = QuotaholderHTTP(QUOTA_HOLDER_URL)
280 288
    timeline = quotaholder.get_timeline(
281
                            context         =   {},
282
                            after           =   after,
283
                            before          =   before,
284
                            get_timeline    =   [[entity, resource, key]])
289
        context={},
290
        after=after,
291
        before=before,
292
        get_timeline=[[entity, resource, key]])
285 293
    cu = charge_units(timeline, after, before, details=details)
286 294
    return cu
287

  

Also available in: Unified diff