Revision 21eb7404
b/snf-cyclades-app/synnefo/quotas/__init__.py | ||
---|---|---|
237 | 237 |
return msg, details |
238 | 238 |
|
239 | 239 |
|
240 |
@transaction.commit_manually
|
|
240 |
@transaction.commit_on_success
|
|
241 | 241 |
def issue_and_accept_commission(resource, delete=False): |
242 | 242 |
"""Issue and accept a commission to Quotaholder. |
243 | 243 |
|
... | ... | |
245 | 245 |
exactly after and in the same transaction that created/updated the |
246 | 246 |
resource. The workflow that implements is the following: |
247 | 247 |
0) Resolve previous unresolved commission if exists |
248 |
1) Issue commission and get a serial |
|
249 |
2) Store the serial in DB and mark is as one to accept |
|
250 |
3) Correlate the serial with the resource |
|
251 |
4) COMMIT! |
|
252 |
5) Accept commission to QH (reject if failed until 5) |
|
253 |
6) Mark serial as resolved |
|
254 |
7) COMMIT! |
|
248 |
1) Issue commission, get a serial and correlate it with the resource |
|
249 |
2) Store the serial in DB as a serial to accept |
|
250 |
3) COMMIT! |
|
251 |
4) Accept commission to QH |
|
255 | 252 |
|
256 | 253 |
""" |
257 |
resolve_commission(resource.serial) |
|
254 |
action = "DESTROY" if delete else "BUILD" |
|
255 |
commission_reason = ("client: api, resource: %s, delete: %s" |
|
256 |
% (resource, delete)) |
|
257 |
serial = handle_resource_commission(resource=resource, action=action, |
|
258 |
commission_name=commission_reason) |
|
258 | 259 |
|
259 |
try: |
|
260 |
action = "DESTROY" if delete else "BUILD" |
|
261 |
# Issue commission and get the assigned serial |
|
262 |
commission_reason = ("client: api, resource: %s, delete: %s" |
|
263 |
% (resource, delete)) |
|
264 |
serial = issue_commission(resource, action, name=commission_reason) |
|
265 |
except: |
|
266 |
transaction.rollback() |
|
267 |
raise |
|
260 |
# Mark the serial as one to accept and associate it with the resource |
|
261 |
serial.pending = False |
|
262 |
serial.accept = True |
|
263 |
serial.save() |
|
264 |
transaction.commit() |
|
268 | 265 |
|
269 | 266 |
try: |
270 |
# Mark the serial as one to accept and associate it with the resource |
|
271 |
serial.pending = False |
|
272 |
serial.accept = True |
|
273 |
serial.save() |
|
274 |
resource.serial = serial |
|
275 |
resource.save() |
|
276 |
transaction.commit() |
|
277 | 267 |
# Accept the commission to quotaholder |
278 | 268 |
accept_serial(serial) |
279 |
transaction.commit() |
|
280 |
return serial |
|
281 | 269 |
except: |
282 |
log.exception("Unexpected ERROR") |
|
283 |
transaction.rollback() |
|
284 |
reject_serial(serial) |
|
285 |
transaction.commit() |
|
286 |
raise |
|
270 |
# Do not crash if we can not accept commission to Quotaholder. Quotas |
|
271 |
# have already been reserved and the resource already exists in DB. |
|
272 |
# Just log the error |
|
273 |
log.exception("Failed to accept commission: %s", serial) |
|
274 |
|
|
275 |
return serial |
|
287 | 276 |
|
288 | 277 |
|
289 | 278 |
def get_commission_info(resource, action, action_fields=None): |
... | ... | |
362 | 351 |
action_fields=action_fields) |
363 | 352 |
resource.serial = serial |
364 | 353 |
resource.save() |
354 |
return serial |
|
365 | 355 |
|
366 | 356 |
|
367 | 357 |
class ResolveError(Exception): |
Also available in: Unified diff