This commit is contained in:
ahmadbilalkhalid 2019-09-07 15:36:01 +05:00
commit 1e9c65ac80
3 changed files with 42 additions and 4 deletions

13
main.py
View file

@ -11,7 +11,7 @@ from flask_restful import Resource, Api
from uuid import uuid4
from os.path import join
from config import etcd_client as client
from config import WITHOUT_CEPH
from config import WITHOUT_CEPH, logging
from ucloud_common.vm import VmPool, VMStatus
from ucloud_common.host import HostPool
@ -131,9 +131,14 @@ class VMAction(Resource):
else:
command_to_delete = ["rbd", "rm", path_without_protocol]
subprocess.check_output(command_to_delete)
except Exception as e:
return {"message": "Some error occurred while deleting VM"}
subprocess.check_output(command_to_delete, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
if "No such file" in e.stderr.decode("utf-8"):
client.client.delete(vm_entry.key)
return {"message": "VM successfully deleted"}
else:
logging.exception(e)
return {"message": "Some error occurred while deleting VM"}
else:
client.client.delete(vm_entry.key)
return {"message": "VM successfully deleted"}