Update hosting_order in a pythonic way

This commit is contained in:
M.Ravi 2018-04-19 07:26:34 +02:00
parent 80c3ac5346
commit fae1c7fbeb

View file

@ -83,20 +83,21 @@ def create_vm_task(self, vm_template_id, user, specs, template, order_id):
# Update HostingOrder with the created vm_id # Update HostingOrder with the created vm_id
hosting_order = HostingOrder.objects.filter(id=order_id).first() hosting_order = HostingOrder.objects.filter(id=order_id).first()
error_msg = None error_msg = None
if hosting_order:
try:
hosting_order.vm_id = vm_id
hosting_order.save()
logger.debug( logger.debug(
"Updating hosting_order {} with vm_id={}".format( "Updated hosting_order {} with vm_id={}".format(
hosting_order.id, vm_id hosting_order.id, vm_id
) )
) )
hosting_order.vm_id = vm_id except Exception as ex:
hosting_order.save()
else:
error_msg = ( error_msg = (
"HostingOrder with id {order_id} not found. This means that " "HostingOrder with id {order_id} not found. This means that "
"the hosting order was not created and/or it is/was not " "the hosting order was not created and/or it is/was not "
"associated with VM with id {vm_id}".format( "associated with VM with id {vm_id}. Details {details}".format(
order_id=order_id, vm_id=vm_id order_id=order_id, vm_id=vm_id, details=str(ex)
) )
) )
logger.error(error_msg) logger.error(error_msg)