Revision fb540e3a snf-cyclades-app/synnefo/quotas/__init__.py
b/snf-cyclades-app/synnefo/quotas/__init__.py | ||
---|---|---|
106 | 106 |
if serial: |
107 | 107 |
serial_info = {"serial": serial} |
108 | 108 |
if auto_accept: |
109 |
serial_info["pending"] = False |
|
109 | 110 |
serial_info["accept"] = True |
110 | 111 |
serial_info["resolved"] = True |
111 | 112 |
return QuotaHolderSerial.objects.create(**serial_info) |
... | ... | |
114 | 115 |
|
115 | 116 |
|
116 | 117 |
def accept_serial(serial, strict=True): |
118 |
assert serial.pending or serial.accept |
|
117 | 119 |
response = resolve_commissions(accept=[serial.serial], strict=strict) |
120 |
serial.pending = False |
|
118 | 121 |
serial.accept = True |
119 | 122 |
serial.resolved = True |
120 | 123 |
serial.save() |
... | ... | |
122 | 125 |
|
123 | 126 |
|
124 | 127 |
def reject_serial(serial, strict=True): |
128 |
assert serial.pending or not serial.accept |
|
125 | 129 |
response = resolve_commissions(reject=[serial.serial], strict=strict) |
126 |
serial.reject = True |
|
130 |
serial.pending = False |
|
131 |
serial.accept = False |
|
127 | 132 |
serial.resolved = True |
128 | 133 |
serial.save() |
129 | 134 |
return response |
... | ... | |
238 | 243 |
7) COMMIT! |
239 | 244 |
|
240 | 245 |
""" |
241 |
previous_serial = resource.serial |
|
242 |
if previous_serial is not None and not previous_serial.resolved: |
|
243 |
if previous_serial.pending: |
|
244 |
msg = "Issuing commission for resource '%s' while previous serial"\ |
|
245 |
" '%s' is still pending." % (resource, previous_serial) |
|
246 |
raise Exception(msg) |
|
247 |
elif previous_serial.accept: |
|
248 |
accept_serial(previous_serial, strict=False) |
|
249 |
else: |
|
250 |
reject_serial(previous_serial, strict=False) |
|
246 |
resolve_commission(resource.serial) |
|
251 | 247 |
|
252 | 248 |
try: |
253 | 249 |
# Convert resources in the format expected by Quotaholder |
... | ... | |
363 | 359 |
|
364 | 360 |
""" |
365 | 361 |
# Try to resolve previous serial |
366 |
resolve_commission(resource.serial) |
|
362 |
resolve_commission(resource.serial, force=force)
|
|
367 | 363 |
|
368 | 364 |
# Check if action is quotable and issue the corresponding commission |
369 | 365 |
serial = None |
... | ... | |
382 | 378 |
resource.serial = serial |
383 | 379 |
|
384 | 380 |
|
385 |
def resolve_commission(serial): |
|
381 |
class ResolveError(Exception): |
|
382 |
pass |
|
383 |
|
|
384 |
|
|
385 |
def resolve_commission(serial, force=False): |
|
386 | 386 |
if serial is None or serial.resolved: |
387 | 387 |
return |
388 |
if serial.pending and not force: |
|
389 |
m = "Could not resolve commission: serial %s is undecided" % serial |
|
390 |
raise ResolveError(m) |
|
388 | 391 |
log.warning("Resolving pending commission: %s", serial) |
389 | 392 |
if not serial.pending and serial.accept: |
390 | 393 |
accept_serial(serial) |
Also available in: Unified diff