Simplify logic

This commit is contained in:
PCoder 2018-09-07 23:11:46 +02:00
parent 7d4cf5c3c2
commit ff6df8cd58

View file

@ -1430,21 +1430,12 @@ class VirtualMachineView(LoginRequiredMixin, View):
break break
else: else:
sleep(2) sleep(2)
if 'status' not in response: if not response['status']:
vm_msg = "VM {} of user {} has not terminated yet!".format( response['details'] = (
vm.id, owner.email "Called VM terminate xml-rpc and waited for over "
"30 seconds for the VM to disappear. But, it did "
"not happen. So, please verify!"
) )
admin_email_body['status'] = vm_msg
logger.error(vm_msg)
err_email_data = {
'subject': vm_msg,
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
'to': ['info@ungleich.ch'],
'body': "Called VM terminate xml-rpc and waited for over "
"30 seconds for the VM to disappear. But, it did "
"not happen. So, please verify!",
}
send_plain_email_task.delay(err_email_data)
context = { context = {
'vm_name': vm_name, 'vm_name': vm_name,
'base_url': "{0}://{1}".format( 'base_url': "{0}://{1}".format(
@ -1465,11 +1456,13 @@ class VirtualMachineView(LoginRequiredMixin, View):
email = BaseEmail(**email_data) email = BaseEmail(**email_data)
email.send() email.send()
admin_email_body.update(response) admin_email_body.update(response)
admin_msg_sub = "VM and Subscription for VM {} and user: {}".format(
vm.id,
owner.email
)
email_to_admin_data = { email_to_admin_data = {
'subject': "Deleted VM and Subscription for VM {vm_id} and " 'subject': ("Deleted " if response['status']
"user: {user}".format( else "ERROR deleting ") + admin_msg_sub,
vm_id=vm.id, user=owner.email
),
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
'to': ['info@ungleich.ch'], 'to': ['info@ungleich.ch'],
'body': "\n".join( 'body': "\n".join(