Commit 9bac9c9d authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Christos Stavrakakis
Browse files

cyclades: Generalize issue_and_accept_commission

Use issue_and_accept_commission for any action where one needs to
automatically accept the commission after issuing and committing.
parent ebf585d5
......@@ -524,7 +524,7 @@ def update_network_state(network):
# Issue commission
if network.userid:
quotas.issue_and_accept_commission(network, delete=True)
quotas.issue_and_accept_commission(network, action="DESTROY")
# the above has already saved the object and committed;
# a second save would override others' changes, since the
# object is now unlocked
......
......@@ -176,7 +176,7 @@ def delete_floating_ip(floating_ip):
floating_ip.deleted = True
floating_ip.save()
# Release quota for floating IP
quotas.issue_and_accept_commission(floating_ip, delete=True)
quotas.issue_and_accept_commission(floating_ip, action="DESTROY")
transaction.commit()
# Delete the floating IP from DB
log.info("Deleted floating IP '%s' of user '%s", floating_ip,
......
......@@ -237,7 +237,7 @@ def render_overlimit_exception(e):
@transaction.commit_on_success
def issue_and_accept_commission(resource, delete=False):
def issue_and_accept_commission(resource, action="BUILD", action_fields=None):
"""Issue and accept a commission to Quotaholder.
This function implements the Commission workflow, and must be called
......@@ -250,10 +250,10 @@ def issue_and_accept_commission(resource, delete=False):
4) Accept commission to QH
"""
action = "DESTROY" if delete else "BUILD"
commission_reason = ("client: api, resource: %s, delete: %s"
% (resource, delete))
commission_reason = ("client: api, resource: %s, action: %s"
% (resource, action))
serial = handle_resource_commission(resource=resource, action=action,
action_fields=action_fields,
commission_name=commission_reason)
# Mark the serial as one to accept and associate it with the resource
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment