1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

clone instance: create db record first, then run clone process. delete db record if exception while cloning

This commit is contained in:
catborise 2018-10-24 16:19:30 +03:00
parent 9d07c2d7b6
commit b5f38afbca

View file

@ -741,11 +741,16 @@ def instance(request, compute_id, vname):
msg = _("Instance mac '%s' invalid format!" % clone_data['clone-net-mac-0'])
error_messages.append(msg)
else:
new_uuid = conn.clone_instance(clone_data)
new_instance = Instance(compute_id=compute_id, name=clone_data['name'], uuid=new_uuid)
new_instance = Instance(compute_id=compute_id, name=clone_data['name'])
new_instance.save()
userinstance = UserInstance(instance_id=new_instance.id, user_id=request.user.id,
is_delete=True)
try:
new_uuid = conn.clone_instance(clone_data)
new_instance.uuid = new_uuid
new_instance.save()
except Exception as e:
new_instance.delete()
raise e
userinstance = UserInstance(instance_id=new_instance.id, user_id=request.user.id, is_delete=True)
userinstance.save()
msg = _("Clone of '%s'" % instance.name)