Revision 14a58548

b/snf-astakos-app/astakos/im/endpoints/qh.py
99 99

  
100 100
def quota_limits_per_user_from_get(lst):
101 101
    quotas = {}
102
    for holder, resource, q, c, il, el, imp, exp, ret, rel, flags in lst:
102
    for holder, resource, q, c, imp, exp, ret, rel, flags in lst:
103 103
        userquotas = quotas.get(holder, {})
104 104
        userquotas[resource] = QuotaValues(quantity=q, capacity=c,
105
                                           import_limit=il, export_limit=el)
105
                                           )
106 106
        quotas[holder] = userquotas
107 107
    return quotas
108 108

  
......
110 110
def quotas_per_user_from_get(lst):
111 111
    limits = {}
112 112
    counters = {}
113
    for holder, resource, q, c, il, el, imp, exp, ret, rel, flags in lst:
113
    for holder, resource, q, c, imp, exp, ret, rel, flags in lst:
114 114
        userlimits = limits.get(holder, {})
115 115
        userlimits[resource] = QuotaValues(quantity=q, capacity=c,
116
                                           import_limit=il, export_limit=el)
116
                                           )
117 117
        limits[holder] = userlimits
118 118

  
119 119
        usercounters = counters.get(holder, {})
......
154 154
                                                 'resource',
155 155
                                                 'quantity',
156 156
                                                 'capacity',
157
                                                 'import_limit',
158
                                                 'export_limit',
159 157
                                                 'flags'))
160 158

  
161 159
QuotaLimits = namedtuple('QuotaLimits', ('holder',
162 160
                                         'resource',
163 161
                                         'capacity',
164
                                         'import_limit',
165
                                         'export_limit'))
162
                                         ))
166 163

  
167 164
QuotaCounters = namedtuple('QuotaCounters', ('imported',
168 165
                                             'exported',
......
172 169

  
173 170
class QuotaValues(namedtuple('QuotaValues', ('quantity',
174 171
                                             'capacity',
175
                                             'import_limit',
176
                                             'export_limit'))):
172
                                             ))):
177 173
    __slots__ = ()
178 174

  
179 175
    def __dir__(self):
180
            return ['quantity', 'capacity', 'import_limit', 'export_limit']
176
            return ['quantity', 'capacity']
181 177

  
182 178
    def __str__(self):
183 179
        return '\t'.join(['%s=%s' % (f, strbigdec(getattr(self, f)))
......
188 184
    return QuotaValues(
189 185
        quantity = q1.quantity + q2.quantity,
190 186
        capacity = q1.capacity + q2.capacity,
191
        import_limit = q1.import_limit + q2.import_limit,
192
        export_limit = q1.export_limit + q2.export_limit)
187
        )
193 188

  
194 189

  
195 190
def register_quotas(quotas):
......
205 200
                    resource=resource,
206 201
                    quantity=q.quantity,
207 202
                    capacity=q.capacity,
208
                    import_limit=q.import_limit,
209
                    export_limit=q.export_limit,
210 203
                    flags=0))
211 204
    return set_quota(payload)
212 205

  
......
224 217
                    resource=resource,
225 218
                    quantity=q.quantity,
226 219
                    capacity=q.capacity,
227
                    import_limit=q.import_limit,
228
                    export_limit=q.export_limit,
229 220
                    flags=0))
230 221
    return set_quota(payload)
231 222

  
......
237 228
            resource=resource,
238 229
            quantity=QH_PRACTICALLY_INFINITE,
239 230
            capacity=QH_PRACTICALLY_INFINITE,
240
            import_limit=QH_PRACTICALLY_INFINITE,
241
            export_limit=QH_PRACTICALLY_INFINITE,
242 231
            flags=0) for resource in resources)
243 232
    return set_quota(payload)
244 233

  
......
254 243

  
255 244
    for ql in sub_list:
256 245
        args = (ql.holder, ql.resource,
257
                0, ql.capacity, ql.import_limit, ql.export_limit)
246
                0, ql.capacity)
258 247
        sub_append(args)
259 248

  
260 249
    for ql in add_list:
261 250
        args = (ql.holder, ql.resource,
262
                0, ql.capacity, ql.import_limit, ql.export_limit)
251
                0, ql.capacity)
263 252
        add_append(args)
264 253

  
265 254
    result = c.add_quota(context=context,
b/snf-astakos-app/astakos/im/management/commands/user-set-initial-quota.py
47 47
AddResourceArgs = namedtuple('AddQuotaArgs', ('resource',
48 48
                                              'capacity',
49 49
                                              'quantity',
50
                                              'import_limit',
51
                                              'export_limit'))
50
                                              ))
52 51

  
53 52
class Command(BaseCommand):
54 53
    help = """Import user quota limits from file or set quota
......
57 56
    The file must contain non-empty lines, and each line must
58 57
    contain a single-space-separated list of values:
59 58

  
60
    <user> <resource name> <capacity> <quantity> <import_limit> <export_limit>
59
    <user> <resource name> <capacity> <quantity>
61 60

  
62 61
    For example to grant the following user with 10 private networks
63 62
    (independent of any he receives from projects):
64 63

  
65
    6119a50b-cbc7-42c0-bafc-4b6570e3f6ac cyclades.network.private 10 0 1000000 1000000
66

  
67
    The last two values are arbitrarily large to represent no
68
    import/export limit at all.
64
    6119a50b-cbc7-42c0-bafc-4b6570e3f6ac cyclades.network.private 10 0
69 65

  
70 66
    When setting quota from the command line, specify only capacity.
71 67
    Quantity and import/export limit will get default values. Example:
......
139 135
        args = AddResourceArgs(resource=resource,
140 136
                               capacity=capacity,
141 137
                               quantity=0,
142
                               import_limit=QH_PRACTICALLY_INFINITE,
143
                               export_limit=QH_PRACTICALLY_INFINITE,
144 138
                               )
145 139

  
146 140
        try:
b/snf-astakos-app/astakos/im/models.py
259 259
    return QuotaValues(
260 260
        quantity = 0,
261 261
        capacity = capacity,
262
        import_limit = QH_PRACTICALLY_INFINITE,
263
        export_limit = QH_PRACTICALLY_INFINITE)
262
        )
264 263

  
265 264
def get_default_quota():
266 265
    _DEFAULT_QUOTA = {}
......
460 459
            p.setdefault('resource', '')
461 460
            p.setdefault('capacity', 0)
462 461
            p.setdefault('quantity', 0)
463
            p.setdefault('import_limit', 0)
464
            p.setdefault('export_limit', 0)
465 462
            p.setdefault('update', True)
466 463
            self.add_resource_policy(**p)
467 464

  
468 465
    def add_resource_policy(
469
            self, resource, capacity, quantity, import_limit,
470
            export_limit, update=True):
466
            self, resource, capacity, quantity,
467
            update=True):
471 468
        """Raises ObjectDoesNotExist, IntegrityError"""
472 469
        s, sep, r = resource.partition(RESOURCE_SEPARATOR)
473 470
        resource = Resource.objects.get(service__name=s, name=r)
......
476 473
                user=self, resource=resource, defaults={
477 474
                    'capacity':capacity,
478 475
                    'quantity': quantity,
479
                    'import_limit':import_limit,
480
                    'export_limit':export_limit})
476
                    })
481 477
        else:
482 478
            q = self.astakosuserquota_set
483 479
            q.create(
484 480
                resource=resource, capacity=capacity, quanity=quantity,
485
                import_limit=import_limit, export_limit=export_limit)
481
                )
486 482

  
487 483
    def get_resource_policy(self, resource):
488 484
        s, sep, r = resource.partition(RESOURCE_SEPARATOR)
......
1066 1062
        return QuotaValues(
1067 1063
            quantity = self.quantity,
1068 1064
            capacity = self.capacity,
1069
            import_limit = self.import_limit,
1070
            export_limit = self.export_limit)
1065
            )
1071 1066

  
1072 1067

  
1073 1068
class ApprovalTerms(models.Model):
......
1792 1787
        return QuotaValues(
1793 1788
            quantity = 0,
1794 1789
            capacity = self.member_capacity,
1795
            import_limit = self.member_import_limit,
1796
            export_limit = self.member_export_limit)
1790
            )
1797 1791

  
1798 1792
    def display_member_capacity(self):
1799 1793
        if self.member_capacity:
......
2295 2289
                               holder       = holder,
2296 2290
                               resource     = str(grant.resource),
2297 2291
                               capacity     = grant.member_capacity,
2298
                               import_limit = grant.member_import_limit,
2299
                               export_limit = grant.member_export_limit))
2292
                               ))
2300 2293

  
2301 2294
        pending_application = self.pending_application
2302 2295
        if pending_application is not None:
......
2306 2299
                               holder       = holder,
2307 2300
                               resource     = str(new_grant.resource),
2308 2301
                               capacity     = new_grant.member_capacity,
2309
                               import_limit = new_grant.member_import_limit,
2310
                               export_limit = new_grant.member_export_limit))
2302
                               ))
2311 2303

  
2312 2304
        return (sub_list, add_list)
2313 2305

  

Also available in: Unified diff