Revert back celery task for delete_vm. Better to do it in another PR.
This commit is contained in:
parent
0634a1a41f
commit
77002a1c9e
1 changed files with 0 additions and 78 deletions
|
@ -1,5 +1,4 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
from celery.exceptions import MaxRetriesExceededError
|
from celery.exceptions import MaxRetriesExceededError
|
||||||
from celery.utils.log import get_task_logger
|
from celery.utils.log import get_task_logger
|
||||||
|
@ -220,80 +219,3 @@ def create_vm_task(self, vm_template_id, user, specs, template,
|
||||||
return
|
return
|
||||||
|
|
||||||
return vm_id
|
return vm_id
|
||||||
|
|
||||||
|
|
||||||
@app.task(bind=True, max_retries=settings.CELERY_MAX_RETRIES)
|
|
||||||
def delete_vm_task(self, user_id, vm_id):
|
|
||||||
return_value = False
|
|
||||||
owner = CustomUser.objects.get(id=user_id)
|
|
||||||
logger.debug(
|
|
||||||
"Running delete_vm_task on {host} for {user} and VM {vm_id}".format(
|
|
||||||
host=current_task.request.hostname, user=owner.email,
|
|
||||||
vm_id=vm_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
manager = OpenNebulaManager(
|
|
||||||
email=owner.email,
|
|
||||||
password=owner.password
|
|
||||||
)
|
|
||||||
|
|
||||||
terminated = manager.delete_vm(vm_id)
|
|
||||||
|
|
||||||
if not terminated:
|
|
||||||
logger.error(
|
|
||||||
"manager.delete_vm returned False. Hence, error making "
|
|
||||||
"xml-rpc call to delete vm failed."
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
logger.debug("Start polling for delete vm")
|
|
||||||
# Time between two get_vm polls in seconds
|
|
||||||
inter_get_vm_poll_time = 5
|
|
||||||
for t in range(15):
|
|
||||||
try:
|
|
||||||
manager.get_vm(vm_id)
|
|
||||||
except BaseException as base_exception:
|
|
||||||
logger.error(
|
|
||||||
"manager.get_vm returned exception: {details}. Hence, "
|
|
||||||
"the vm with id {vm_id} is no more accessible".format(
|
|
||||||
details=str(base_exception), vm_id=vm_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return_value = True
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
logger.debug(
|
|
||||||
"VM {vm_id} is still accessible. So, sleeping for "
|
|
||||||
"{sleep_time} and then retrying".format(
|
|
||||||
vm_id=vm_id, sleep_time=inter_get_vm_poll_time
|
|
||||||
)
|
|
||||||
)
|
|
||||||
sleep(inter_get_vm_poll_time)
|
|
||||||
if return_value is False:
|
|
||||||
raise Exception("Could not delete vm {}".format(vm_id))
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(
|
|
||||||
"An exception occurred while deleting VM {vm_id}. Details "
|
|
||||||
"below".format(
|
|
||||||
vm_id=vm_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
logger.error(str(e))
|
|
||||||
try:
|
|
||||||
retry_task(self)
|
|
||||||
except MaxRetriesExceededError:
|
|
||||||
msg_text = 'Finished {} retries for delete_vm_task'.format(
|
|
||||||
self.request.retries
|
|
||||||
)
|
|
||||||
logger.error(msg_text)
|
|
||||||
# Try sending email and stop
|
|
||||||
email_data = {
|
|
||||||
'subject': '{} CELERY TASK ERROR: {}'.format(settings.DCL_TEXT,
|
|
||||||
msg_text),
|
|
||||||
'from_email': current_task.request.hostname,
|
|
||||||
'to': settings.DCL_ERROR_EMAILS_TO_LIST,
|
|
||||||
'body': ',\n'.join(str(i) for i in self.request.args)
|
|
||||||
}
|
|
||||||
email = EmailMessage(**email_data)
|
|
||||||
email.send()
|
|
||||||
return return_value
|
|
||||||
|
|
Loading…
Reference in a new issue