Commit 6554b86a authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Restore quotas if enqueuing job to Ganeti fails

When creating a server, we commit the VM model in DB and reserve the
corresponding quotas in Quotaholder before enqueuing the
OP_INSTANCE_CREATE job (because messages from dispatcher may arrive
before committing). In case enqueuing job to Ganeti fails we must
restore the quotas to their previous value. This commit achieves this by
issuing a "delete" commission for the VM. Also, instead of deleting the
VM entry, we mark the VM as deleted, in order to keep the relation
with the Quotaholder serial.
parent 3d6a5fb4
......@@ -366,10 +366,15 @@ def create_server(request):
log.info("User %s created VM %s, NIC %s, Backend %s, JobID %s",
user_id, vm, nic, backend, str(jobID))
except GanetiApiError as e:
log.exception("Can not communicate to backend %s: %s. Deleting VM %s",
backend, e, vm)
vm.delete()
transaction.commit()
log.exception("Can not communicate to backend %s: %s.",
backend, e)
# Failed while enqueuing OP_INSTANCE_CREATE to backend. Restore
# already reserved quotas by issuing a negative commission
vm.operstate = "ERROR"
vm.backendlogmsg = "Can not communicate to backend."
vm.deleted = True
vm.save()
quotas.issue_and_accept_commission(vm, delete=True)
raise
except:
transaction.rollback()
......
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