From a5cdfab306e86f44ae3c9ba1d0f9e1eaed0051fe Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 25 Jul 2018 21:53:33 +0200 Subject: [PATCH] Send an email to admin if the VM is still there after 30 seconds of the VM terminate calll --- hosting/views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index f2c51cf5..476c62ff 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1404,6 +1404,9 @@ class VirtualMachineView(LoginRequiredMixin, View): try: manager.get_vm(vm.id) except WrongIdError: + logger.error( + "VM {} not found. So, its terminated.".format(vm.id) + ) response['status'] = True response['text'] = ugettext('Terminated') vm_detail_obj = VMDetail.objects.filter( @@ -1421,6 +1424,19 @@ class VirtualMachineView(LoginRequiredMixin, View): break else: sleep(2) + if 'status' not in response: + vm_msg = "VM {} has not terminated yet!".format(vm.id) + 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 = { 'vm_name': vm_name, 'base_url': "{0}://{1}".format(