Revision 5c8076b6 snf-cyclades-app/synnefo/quotas/__init__.py
b/snf-cyclades-app/synnefo/quotas/__init__.py | ||
---|---|---|
349 | 349 |
return dict((r, -s) for r, s in resources.items()) |
350 | 350 |
|
351 | 351 |
|
352 |
def resolve_vm_commission(serial): |
|
352 |
def handle_resource_commission(resource, action, commission_name, |
|
353 |
commission_info=None, force=False, |
|
354 |
auto_accept=False): |
|
355 |
"""Handle a issuing of a commission for a resource. |
|
356 |
|
|
357 |
Create a new commission for a resource based on the action that |
|
358 |
is performed. If the resource has a previous pending commission, |
|
359 |
resolved it before issuing the new one. |
|
360 |
|
|
361 |
""" |
|
362 |
# Try to resolve previous serial |
|
363 |
resolve_commission(resource.serial) |
|
364 |
|
|
365 |
# Check if action is quotable and issue the corresponding commission |
|
366 |
serial = None |
|
367 |
if commission_info is None: |
|
368 |
commission_info = get_commission_info(resource, action=action) |
|
369 |
if commission_info is not None: |
|
370 |
# Issue new commission, associate it with the resource |
|
371 |
if commission_name is None: |
|
372 |
commission_name = "client: api, resource %s" % resource |
|
373 |
serial = issue_commission(user=resource.userid, |
|
374 |
source=DEFAULT_SOURCE, |
|
375 |
provisions=commission_info, |
|
376 |
name=commission_name, |
|
377 |
force=False, |
|
378 |
auto_accept=False) |
|
379 |
resource.serial = serial |
|
380 |
|
|
381 |
|
|
382 |
def resolve_commission(serial): |
|
383 |
if serial is None or serial.resolved: |
|
384 |
return |
|
353 | 385 |
log.warning("Resolving pending commission: %s", serial) |
354 | 386 |
if not serial.pending and serial.accept: |
355 | 387 |
accept_serial(serial) |
Also available in: Unified diff