Revision d1304043 kamaki/clients/quotaholder/api/quotaholder.py

b/kamaki/clients/quotaholder/api/quotaholder.py
34 34
# or implied, of GRNET S.A.
35 35

  
36 36

  
37
from kamaki.clients.commissioning import (CanonifyException, SpecifyException,
38
                                       Specificator, Null, Integer, Text,
39
                                       Tuple, ListOf, Dict, Args)
37
from kamaki.clients.commissioning import (
38
    CanonifyException,
39
    SpecifyException,
40
    Specificator,
41
    Null,
42
    Integer,
43
    Text,
44
    Tuple,
45
    ListOf,
46
    Dict,
47
    Args)
40 48
from random import choice, randint
41 49

  
42
Context             =   Dict(classname='Context', null=True, show=False)
50
Context = Dict(classname='Context', null=True, show=False)
51

  
43 52

  
44 53
class Name(Text):
45 54
    def init(self):
46
        self.opts.update({'regex': "[\w.:@+/-]+", 'maxlen':512})
55
        self.opts.update({'regex': "[\w.:@+/-]+", 'maxlen': 512})
47 56
        Text.init(self)
48 57

  
49 58
    def _random_choice(self, kw):
......
51 60
        length = randint(1, 48)
52 61
        return ''.join(choice(alphabet) for _ in xrange(length))
53 62

  
63

  
54 64
class Nonnegative(Integer):
55 65
    def init(self):
56 66
        self.opts.update({'minimum': 0})
57 67

  
68

  
58 69
class Positive(Integer):
59 70
    def init(self):
60 71
        self.opts.update({'minimum': 1})
61 72

  
62
Serial              =   Positive(classname='Serial')
63

  
64
ClientKey           =   Name(classname='ClientKey')
65
Nothing             =   Null(classname='Nothing')
66

  
67
Entity              =   Name(classname='Entity')
68
Owner               =   Name(classname='Owner')
69
Key                 =   Text(classname='Key')
70
NewKey              =   Text(classname='Newkey')
71
OwnerKey            =   Text(classname='OwnerKey')
72
Resource            =   Name(classname='Resource')
73
Policy              =   Name(classname='Policy')
74

  
75
Quantity            =   Integer(classname='Quantity', null=True)
76
Capacity            =   Nonnegative(classname='Capacity', null=True)
77
ImportLimit         =   Nonnegative(classname='ImportLimit', null=True)
78
ExportLimit         =   Nonnegative(classname='ExportLimit', null=True)
79
Imported            =   Nonnegative(classname='Imported')
80
Exported            =   Nonnegative(classname='Exported')
81
Returned            =   Nonnegative(classname='Returned')
82
Released            =   Nonnegative(classname='Released')
83
Flags               =   Nonnegative(classname='Flags')
84
Index               =   Nonnegative(classname='Index')
85

  
86
Timepoint           =   Text(classname='Timepoint', maxlen=24)
87
Reason              =   Text(   classname   =   'Reason',
88
                                regex       =   '(ACCEPT|REJECT):.*',
89
                                maxlen      =   128         )
73

  
74
QH_PRACTICALLY_INFINITE = 10**32
75

  
76
Serial = Positive(classname='Serial')
77

  
78
ClientKey = Name(classname='ClientKey')
79
Nothing = Null(classname='Nothing')
80

  
81
Entity = Name(classname='Entity')
82
Owner = Name(classname='Owner')
83
Key = Text(classname='Key')
84
NewKey = Text(classname='Newkey')
85
OwnerKey = Text(classname='OwnerKey')
86
Resource = Name(classname='Resource')
87
Policy = Name(classname='Policy')
88

  
89
Quantity = Integer(classname='Quantity')
90
Capacity = Nonnegative(classname='Capacity')
91
ImportLimit = Nonnegative(classname='ImportLimit')
92
ExportLimit = Nonnegative(classname='ExportLimit')
93
QuantityDelta = Integer(classname='QuantityDelta')
94
CapacityDelta = Integer(classname='CapacityDelta')
95
ImportLimitDelta = Integer(classname='ImportLimitDelta')
96
ExportLimitDelta = Integer(classname='ExportLimitDelta')
97
Imported = Nonnegative(classname='Imported')
98
Exported = Nonnegative(classname='Exported')
99
Returned = Nonnegative(classname='Returned')
100
Released = Nonnegative(classname='Released')
101
Flags = Nonnegative(classname='Flags')
102
Index = Nonnegative(classname='Index')
103

  
104
Timepoint = Text(classname='Timepoint', maxlen=24)
105
Reason = Text(classname='Reason', regex='(ACCEPT|REJECT):.*', maxlen=128)
106

  
90 107

  
91 108
class QuotaholderAPI(Specificator):
92 109

  
93
    def create_entity   (
94
                self,
95
                context         =   Context,
96
                create_entity   =   ListOf(Entity, Owner, Key, OwnerKey, nonempty=1)
97
        ):
110
    def create_entity(
111
        self,
112
        context=Context,
113
        create_entity=ListOf(Entity, Owner, Key, OwnerKey,
114
        nonempty=1)
115
    ):
98 116
        rejected = ListOf(Index)
99 117
        return rejected
100 118

  
101
    def set_entity_key  (
102
                self,
103
                context         =   Context,
104
                set_entity_key  =   ListOf(Entity, Key, NewKey)
105
        ):
119
    def set_entity_key(
120
        self,
121
        context=Context,
122
        set_entity_key=ListOf(Entity, Key, NewKey)
123
    ):
106 124
        rejected = ListOf(Entity)
107 125
        return rejected
108 126

  
109
    def list_entities   (
110
                self,
111
                context         =   Context,
112
                entity          =   Entity,
113
                key             =   Key
114
        ):
127
    def list_entities(
128
        self,
129
        context=Context,
130
        entity=Entity,
131
        key=Key
132
    ):
115 133
        entities = ListOf(Entity)
116 134
        return entities
117 135

  
118
    def get_entity  (
119
                self,
120
                context     =   Context,
121
                get_entity  =   ListOf(Entity, Key, nonempty=1)
122
        ):
136
    def get_entity(
137
        self,
138
        context=Context,
139
        get_entity=ListOf(Entity, Key, nonempty=1)
140
    ):
123 141
        entities = ListOf(Entity, Owner)
124 142
        return entities
125 143

  
126
    def get_limits  (
127
                self,
128
                context     =   Context,
129
                get_limits  =   ListOf(Policy, nonempty=1)
130
        ):
144
    def get_limits(
145
        self,
146
        context=Context,
147
        get_limits=ListOf(Policy, nonempty=1)
148
    ):
131 149
        limits = ListOf(Policy, Quantity, Capacity,
132 150
                        ImportLimit, ExportLimit)
133 151
        return limits
134 152

  
135
    def set_limits  (
136
                self,
137
                context     =   Context,
138
                set_limits  =   ListOf( Policy, Quantity, Capacity,
139
                                        ImportLimit, ExportLimit,
140
                                        nonempty=1 )
141
        ):
153
    def set_limits(
154
        self,
155
        context=Context,
156
        set_limits=ListOf(
157
            Policy,
158
            Quantity,
159
            Capacity,
160
            ImportLimit,
161
            ExportLimit,
162
            nonempty=1)
163
    ):
142 164
        rejected = ListOf(Policy)
143 165
        return rejected
144 166

  
145
    def get_holding (
146
                self,
147
                context     =   Context,
148
                get_holding =   ListOf(Entity, Resource, Key)
149
        ):
167
    def get_holding(
168
        self,
169
        context=Context,
170
        get_holding=ListOf(Entity, Resource, Key)
171
    ):
150 172
        holdings = ListOf(  Entity, Resource, Policy,
151 173
                            Imported, Exported, Returned, Released, Flags   )
152 174
        return holdings
153 175

  
154
    def set_holding (
155
                self,
156
                context     =   Context,
157
                set_holding =   ListOf(Entity, Resource, Key, Policy, Flags)
158
        ):
176
    def set_holding(
177
        self,
178
        context=Context,
179
        set_holding=ListOf(Entity, Resource, Key, Policy, Flags)
180
    ):
159 181
        rejected = ListOf(Entity, Resource, Policy)
160 182
        return rejected
161 183

  
162
    def init_holding (
163
                self,
164
                context      =   Context,
165
                init_holding =   ListOf(Entity, Resource, Key, Policy,
166
                                        Imported, Exported, Returned, Released,
167
                                        Flags)
168
        ):
184
    def init_holding(
185
        self,
186
        context=Context,
187
        init_holding=ListOf(
188
            Entity,
189
            Resource,
190
            Key,
191
            Policy,
192
            Imported,
193
            Exported,
194
            Returned,
195
            Released,
196
            Flags)
197
    ):
169 198
        rejected = ListOf(Index)
170 199
        return rejected
171 200

  
172
    def reset_holding (
173
                self,
174
                context       =   Context,
175
                reset_holding =   ListOf(Entity, Resource, Key,
176
                                        Imported, Exported, Returned, Released)
177
        ):
201
    def reset_holding(
202
        self,
203
        context=Context,
204
        reset_holding=ListOf(
205
            Entity,
206
            Resource,
207
            Key,
208
            Imported,
209
            Exported,
210
            Returned,
211
            Released)
212
    ):
178 213
        rejected = ListOf(Index)
179 214
        return rejected
180 215

  
181
    def release_holding (
182
                self,
183
                context         =   Context,
184
                release_holding =   ListOf(Entity, Resource, Key)
185
        ):
216
    def release_holding(
217
        self,
218
        context=Context,
219
        release_holding=ListOf(Entity, Resource, Key)
220
    ):
186 221
        rejected = ListOf(Index)
187 222
        return rejected
188 223

  
189
    def list_resources  (
190
                self,
191
                context     =   Context,
192
                entity      =   Entity,
193
                key         =   Key
194
        ):
224
    def list_resources(self, context=Context, entity=Entity, key=Key):
195 225
        resources = ListOf(Resource)
196 226
        return resources
197 227

  
198
    def list_holdings   (
199
                self,
200
                context         =   Context,
201
                list_holdings   =   ListOf(Entity, Key)
202
        ):
203

  
228
    def list_holdings(
229
        self,
230
        context=Context,
231
        list_holdings=ListOf(Entity, Key)
232
    ):
204 233
        rejected = ListOf(Entity)
205 234
        holdings_list = ListOf(ListOf(Entity, Resource,
206 235
                                      Imported, Exported,
207 236
                                      Returned, Released))
208 237
        return Tuple(holdings_list, rejected)
209 238

  
210
    def get_quota   (
211
                self,
212
                context     =   Context,
213
                get_quota   =   ListOf(Entity, Resource, Key)
214
        ):
239
    def get_quota(
240
        self,
241
        context=Context,
242
        get_quota=ListOf(Entity, Resource, Key)
243
    ):
215 244
        quotas = ListOf(Entity, Resource,
216 245
                        Quantity, Capacity,
217 246
                        ImportLimit, ExportLimit,
......
220 249
                        Flags)
221 250
        return quotas
222 251

  
223
    def set_quota   (
224
                self,
225
                context     =   Context,
226
                set_quota   =   ListOf( Entity, Resource, Key,
227
                                        Quantity, Capacity,
228
                                        ImportLimit, ExportLimit, Flags )
229
        ):
252
    def set_quota(
253
        self,
254
        context=Context,
255
        set_quota=ListOf(
256
            Entity,
257
            Resource,
258
            Key,
259
            Quantity,
260
            Capacity,
261
            ImportLimit,
262
            ExportLimit,
263
            Flags)
264
    ):
265
        rejected = ListOf(Entity, Resource)
266
        return rejected
267

  
268
    def add_quota(
269
        self,
270
        context=Context,
271
        clientkey=ClientKey,
272
        serial=Serial,
273
        sub_quota=ListOf(
274
            Entity,
275
            Resource,
276
            Key,
277
            QuantityDelta,
278
            CapacityDelta,
279
            ImportLimitDelta,
280
            ExportLimitDelta),
281
        add_quota=ListOf(
282
            Entity,
283
            Resource,
284
            Key,
285
            QuantityDelta,
286
            CapacityDelta,
287
            ImportLimitDelta,
288
            ExportLimitDelta)
289
    ):
230 290
        rejected = ListOf(Entity, Resource)
231 291
        return rejected
232 292

  
233
    def issue_commission    (
234
                self,
235
                context     =   Context,
236
                target      =   Entity,
237
                key         =   Key,
238
                clientkey   =   ClientKey,
239
                name        =   Text(default=''),
240
                provisions  =   ListOf(Entity, Resource, Quantity)
241
        ):
293
    def query_serials(
294
        self,
295
        context=Context,
296
        clientkey=ClientKey,
297
        serials=ListOf(Serial)
298
    ):
299
        return ListOf(Serial)
300

  
301
    def ack_serials(
302
        self,
303
        context=Context,
304
        clientkey=ClientKey,
305
        serials=ListOf(Serial)
306
    ):
307
        return Nothing
308

  
309
    def issue_commission(
310
        self,
311
        context=Context,
312
        target=Entity,
313
        key=Key,
314
        clientkey=ClientKey,
315
        name=Text(default=''),
316
        provisions=ListOf(Entity, Resource, Quantity)
317
    ):
242 318
        return Serial
243 319

  
244
    def accept_commission   (
245
                self,
246
                context     =   Context,
247
                clientkey   =   ClientKey,
248
                serials     =   ListOf(Serial),
249
                reason      =   Text(default='ACCEPT')
250
        ):
320
    def accept_commission(
321
        self,
322
        context=Context,
323
        clientkey=ClientKey,
324
        serials=ListOf(Serial),
325
        reason=Text(default='ACCEPT')
326
    ):
251 327
        return Nothing
252 328

  
253
    def reject_commission   (
254
                self,
255
                context     =   Context,
256
                clientkey   =   ClientKey,
257
                serials     =   ListOf(Serial),
258
                reason      =   Text(default='REJECT')
259
        ):
329
    def reject_commission(
330
        self,
331
        context=Context,
332
        clientkey=ClientKey,
333
        serials=ListOf(Serial),
334
        reason=Text(default='REJECT')
335
    ):
260 336
        return Nothing
261 337

  
262
    def get_pending_commissions (
263
                    self,
264
                    context     =   Context,
265
                    clientkey   =   ClientKey
266
        ):
338
    def get_pending_commissions(
339
        self,
340
        context=Context,
341
        clientkey=ClientKey
342
    ):
267 343
        pending = ListOf(Serial)
268 344
        return pending
269 345

  
270
    def resolve_pending_commissions (
271
                    self,
272
                    context     =   Context,
273
                    clientkey   =   ClientKey,
274
                    max_serial  =   Serial,
275
                    accept_set  =   ListOf(Serial)
276
        ):
346
    def resolve_pending_commissions(
347
        self,
348
        context=Context,
349
        clientkey=ClientKey,
350
        max_serial=Serial,
351
        accept_set=ListOf(Serial)
352
    ):
277 353
        return Nothing
278 354

  
279
    def release_entity  (
280
                self,
281
                context         =   Context,
282
                release_entity  =   ListOf(Entity, Key, nonempty=1)
283
        ):
355
    def release_entity(
356
        self,
357
        context=Context,
358
        release_entity=ListOf(Entity, Key, nonempty=1)
359
    ):
284 360
        rejected = ListOf(Entity)
285 361
        return rejected
286 362

  
287
    def get_timeline    (
288
                self,
289
                context         =   Context,
290
                after           =   Timepoint,
291
                before          =   Timepoint,
292
                get_timeline    =   ListOf(Entity, Resource, Key)
293
        ):
363
    def get_timeline(
364
        self,
365
        context=Context,
366
        after=Timepoint,
367
        before=Timepoint,
368
        get_timeline=ListOf(Entity, Resource, Key)
369
    ):
294 370
        timeline = ListOf(Dict(
295
                            serial                      =   Serial,
296
                            source                      =   Entity,
297
                            target                      =   Entity,
298
                            resource                    =   Resource,
299
                            name                        =   Name(),
300
                            quantity                    =   Quantity,
301
                            source_allocated            =   Quantity,
302
                            source_allocated_through    =   Quantity,
303
                            source_inbound              =   Quantity,
304
                            source_inbound_through      =   Quantity,
305
                            source_outbound             =   Quantity,
306
                            source_outbound_through     =   Quantity,
307
                            target_allocated            =   Quantity,
308
                            target_allocated_through    =   Quantity,
309
                            target_inbound              =   Quantity,
310
                            target_inbound_through      =   Quantity,
311
                            target_outbound             =   Quantity,
312
                            target_outbound_through     =   Quantity,
313
                            issue_time                  =   Timepoint,
314
                            log_time                    =   Timepoint,
315
                            reason                      =   Reason,
316

  
317
                            strict  =   True))
371
            serial=Serial,
372
            source=Entity,
373
            target=Entity,
374
            resource=Resource,
375
            name=Name(),
376
            quantity=Quantity,
377
            source_allocated=Quantity,
378
            source_allocated_through=Quantity,
379
            source_inbound=Quantity,
380
            source_inbound_through=Quantity,
381
            source_outbound=Quantity,
382
            source_outbound_through=Quantity,
383
            target_allocated=Quantity,
384
            target_allocated_through=Quantity,
385
            target_inbound=Quantity,
386
            target_inbound_through=Quantity,
387
            target_outbound=Quantity,
388
            target_outbound_through=Quantity,
389
            issue_time=Timepoint,
390
            log_time=Timepoint,
391
            reason=Reason,
392
            strict=True))
318 393
        return timeline
319

  

Also available in: Unified diff