root / snf-common / synnefo / lib / quotaholder / api / quotaholder.py @ ccdb658a
History | View | Annotate | Download (10.8 kB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
#
|
3 |
# Copyright 2012 GRNET S.A. All rights reserved.
|
4 |
#
|
5 |
# Redistribution and use in source and binary forms, with or
|
6 |
# without modification, are permitted provided that the following
|
7 |
# conditions are met:
|
8 |
#
|
9 |
# 1. Redistributions of source code must retain the above
|
10 |
# copyright notice, this list of conditions and the following
|
11 |
# disclaimer.
|
12 |
#
|
13 |
# 2. Redistributions in binary form must reproduce the above
|
14 |
# copyright notice, this list of conditions and the following
|
15 |
# disclaimer in the documentation and/or other materials
|
16 |
# provided with the distribution.
|
17 |
#
|
18 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
19 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
21 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
22 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
25 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
26 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
27 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
28 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
# POSSIBILITY OF SUCH DAMAGE.
|
30 |
#
|
31 |
# The views and conclusions contained in the software and
|
32 |
# documentation are those of the authors and should not be
|
33 |
# interpreted as representing official policies, either expressed
|
34 |
# or implied, of GRNET S.A.
|
35 |
|
36 |
|
37 |
from synnefo.lib.commissioning import (CanonifyException, SpecifyException, |
38 |
Specificator, Null, Integer, Text, |
39 |
Tuple, ListOf, Dict, Args) |
40 |
from random import choice, randint |
41 |
|
42 |
Context = Dict(classname='Context', null=True, show=False) |
43 |
|
44 |
class Name(Text): |
45 |
def init(self): |
46 |
self.opts.update({'regex': "[\w.:@+/-]+", 'maxlen':512}) |
47 |
Text.init(self)
|
48 |
|
49 |
def _random_choice(self, kw): |
50 |
alphabet = u'abcdef_1233490.:@/-αβγδεζ'
|
51 |
length = randint(1, 48) |
52 |
return ''.join(choice(alphabet) for _ in xrange(length)) |
53 |
|
54 |
class Nonnegative(Integer): |
55 |
def init(self): |
56 |
self.opts.update({'minimum': 0}) |
57 |
|
58 |
class Positive(Integer): |
59 |
def init(self): |
60 |
self.opts.update({'minimum': 1}) |
61 |
|
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 )
|
90 |
|
91 |
class QuotaholderAPI(Specificator): |
92 |
|
93 |
def create_entity ( |
94 |
self,
|
95 |
context = Context, |
96 |
create_entity = ListOf(Entity, Owner, Key, OwnerKey, nonempty=1)
|
97 |
): |
98 |
rejected = ListOf(Index) |
99 |
return rejected
|
100 |
|
101 |
def set_entity_key ( |
102 |
self,
|
103 |
context = Context, |
104 |
set_entity_key = ListOf(Entity, Key, NewKey) |
105 |
): |
106 |
rejected = ListOf(Entity) |
107 |
return rejected
|
108 |
|
109 |
def list_entities ( |
110 |
self,
|
111 |
context = Context, |
112 |
entity = Entity, |
113 |
key = Key |
114 |
): |
115 |
entities = ListOf(Entity) |
116 |
return entities
|
117 |
|
118 |
def get_entity ( |
119 |
self,
|
120 |
context = Context, |
121 |
get_entity = ListOf(Entity, Key, nonempty=1)
|
122 |
): |
123 |
entities = ListOf(Entity, Owner) |
124 |
return entities
|
125 |
|
126 |
def get_limits ( |
127 |
self,
|
128 |
context = Context, |
129 |
get_limits = ListOf(Policy, nonempty=1)
|
130 |
): |
131 |
limits = ListOf(Policy, Quantity, Capacity, |
132 |
ImportLimit, ExportLimit) |
133 |
return limits
|
134 |
|
135 |
def set_limits ( |
136 |
self,
|
137 |
context = Context, |
138 |
set_limits = ListOf( Policy, Quantity, Capacity, |
139 |
ImportLimit, ExportLimit, |
140 |
nonempty=1 )
|
141 |
): |
142 |
rejected = ListOf(Policy) |
143 |
return rejected
|
144 |
|
145 |
def get_holding ( |
146 |
self,
|
147 |
context = Context, |
148 |
get_holding = ListOf(Entity, Resource, Key) |
149 |
): |
150 |
holdings = ListOf( Entity, Resource, Policy, |
151 |
Imported, Exported, Returned, Released, Flags ) |
152 |
return holdings
|
153 |
|
154 |
def set_holding ( |
155 |
self,
|
156 |
context = Context, |
157 |
set_holding = ListOf(Entity, Resource, Key, Policy, Flags) |
158 |
): |
159 |
rejected = ListOf(Entity, Resource, Policy) |
160 |
return rejected
|
161 |
|
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 |
): |
169 |
rejected = ListOf(Index) |
170 |
return rejected
|
171 |
|
172 |
def release_holding ( |
173 |
self,
|
174 |
context = Context, |
175 |
release_holding = ListOf(Entity, Resource, Key) |
176 |
): |
177 |
rejected = ListOf(Index) |
178 |
return rejected
|
179 |
|
180 |
def list_resources ( |
181 |
self,
|
182 |
context = Context, |
183 |
entity = Entity, |
184 |
key = Key |
185 |
): |
186 |
resources = ListOf(Resource) |
187 |
return resources
|
188 |
|
189 |
def get_quota ( |
190 |
self,
|
191 |
context = Context, |
192 |
get_quota = ListOf(Entity, Resource, Key) |
193 |
): |
194 |
quotas = ListOf(Entity, Resource, |
195 |
Quantity, Capacity, |
196 |
ImportLimit, ExportLimit, |
197 |
Imported, Exported, |
198 |
Returned, Released, |
199 |
Flags) |
200 |
return quotas
|
201 |
|
202 |
def set_quota ( |
203 |
self,
|
204 |
context = Context, |
205 |
set_quota = ListOf( Entity, Resource, Key, |
206 |
Quantity, Capacity, |
207 |
ImportLimit, ExportLimit, Flags ) |
208 |
): |
209 |
rejected = ListOf(Entity, Resource) |
210 |
return rejected
|
211 |
|
212 |
def issue_commission ( |
213 |
self,
|
214 |
context = Context, |
215 |
target = Entity, |
216 |
key = Key, |
217 |
clientkey = ClientKey, |
218 |
name = Text(default=''),
|
219 |
provisions = ListOf(Entity, Resource, Quantity) |
220 |
): |
221 |
return Serial
|
222 |
|
223 |
def accept_commission ( |
224 |
self,
|
225 |
context = Context, |
226 |
clientkey = ClientKey, |
227 |
serials = ListOf(Serial), |
228 |
reason = Text(default='ACCEPT')
|
229 |
): |
230 |
return Nothing
|
231 |
|
232 |
def reject_commission ( |
233 |
self,
|
234 |
context = Context, |
235 |
clientkey = ClientKey, |
236 |
serials = ListOf(Serial), |
237 |
reason = Text(default='REJECT')
|
238 |
): |
239 |
return Nothing
|
240 |
|
241 |
def get_pending_commissions ( |
242 |
self,
|
243 |
context = Context, |
244 |
clientkey = ClientKey |
245 |
): |
246 |
pending = ListOf(Serial) |
247 |
return pending
|
248 |
|
249 |
def resolve_pending_commissions ( |
250 |
self,
|
251 |
context = Context, |
252 |
clientkey = ClientKey, |
253 |
max_serial = Serial, |
254 |
accept_set = ListOf(Serial) |
255 |
): |
256 |
return Nothing
|
257 |
|
258 |
def release_entity ( |
259 |
self,
|
260 |
context = Context, |
261 |
release_entity = ListOf(Entity, Key, nonempty=1)
|
262 |
): |
263 |
rejected = ListOf(Entity) |
264 |
return rejected
|
265 |
|
266 |
def get_timeline ( |
267 |
self,
|
268 |
context = Context, |
269 |
after = Timepoint, |
270 |
before = Timepoint, |
271 |
get_timeline = ListOf(Entity, Resource, Key) |
272 |
): |
273 |
timeline = ListOf(Dict( |
274 |
serial = Serial, |
275 |
source = Entity, |
276 |
target = Entity, |
277 |
resource = Resource, |
278 |
name = Name(), |
279 |
quantity = Quantity, |
280 |
source_allocated = Quantity, |
281 |
source_allocated_through = Quantity, |
282 |
source_inbound = Quantity, |
283 |
source_inbound_through = Quantity, |
284 |
source_outbound = Quantity, |
285 |
source_outbound_through = Quantity, |
286 |
target_allocated = Quantity, |
287 |
target_allocated_through = Quantity, |
288 |
target_inbound = Quantity, |
289 |
target_inbound_through = Quantity, |
290 |
target_outbound = Quantity, |
291 |
target_outbound_through = Quantity, |
292 |
issue_time = Timepoint, |
293 |
log_time = Timepoint, |
294 |
reason = Reason, |
295 |
|
296 |
strict = True))
|
297 |
return timeline
|
298 |
|