Refactor some code
This commit is contained in:
parent
b4e26ac51f
commit
8356c3bf95
1 changed files with 16 additions and 9 deletions
|
@ -233,15 +233,14 @@ def delete_vm_task(self, user_id, vm_id):
|
||||||
vm_id=vm_id
|
vm_id=vm_id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
manager = OpenNebulaManager(
|
|
||||||
email=owner.email,
|
|
||||||
password=owner.password
|
|
||||||
)
|
|
||||||
|
|
||||||
terminated = manager.delete_vm(vm_id)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
manager = OpenNebulaManager(
|
||||||
|
email=owner.email,
|
||||||
|
password=owner.password
|
||||||
|
)
|
||||||
|
|
||||||
|
terminated = manager.delete_vm(vm_id)
|
||||||
|
|
||||||
if not terminated:
|
if not terminated:
|
||||||
logger.error(
|
logger.error(
|
||||||
"manager.delete_vm returned False. Hence, error making "
|
"manager.delete_vm returned False. Hence, error making "
|
||||||
|
@ -249,6 +248,8 @@ def delete_vm_task(self, user_id, vm_id):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.debug("Start polling for delete vm")
|
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):
|
for t in range(15):
|
||||||
try:
|
try:
|
||||||
manager.get_vm(vm_id)
|
manager.get_vm(vm_id)
|
||||||
|
@ -262,7 +263,13 @@ def delete_vm_task(self, user_id, vm_id):
|
||||||
return_value = True
|
return_value = True
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
sleep(5)
|
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:
|
if return_value is False:
|
||||||
raise Exception("Could not delete vm {}".format(vm_id))
|
raise Exception("Could not delete vm {}".format(vm_id))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue