a
This commit is contained in:
parent
bc803d5c08
commit
fefee23a5a
3 changed files with 17 additions and 8 deletions
21
main.py
21
main.py
|
|
@ -4,12 +4,14 @@
|
|||
|
||||
import json
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
from flask import Flask, request
|
||||
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 ucloud_common.vm import VmPool, VMStatus
|
||||
from ucloud_common.host import HostPool
|
||||
|
|
@ -123,15 +125,18 @@ class VMAction(Resource):
|
|||
if action == "delete" and vm_entry.hostname == "":
|
||||
try:
|
||||
path_without_protocol = vm_entry.path[vm_entry.path.find(":")+1:]
|
||||
rc = subprocess.call(f"rbd rm {path_without_protocol}".split(" "))
|
||||
except FileNotFoundError:
|
||||
return {"message": "VM image does not exists"}
|
||||
else:
|
||||
if rc == 0:
|
||||
client.client.delete(vm_entry.key)
|
||||
return {"message": "VM successfully deleted"}
|
||||
|
||||
if WITHOUT_CEPH:
|
||||
command_to_delete = ["rm", os.path.join("/var/vm", vm_entry.uuid)]
|
||||
else:
|
||||
return {"message": "Some error occurred while deleting VM"}
|
||||
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"}
|
||||
else:
|
||||
client.client.delete(vm_entry.key)
|
||||
return {"message": "VM successfully deleted"}
|
||||
|
||||
r = RequestEntry.from_scratch(type=f"{action.title()}VM",
|
||||
uuid=data['uuid'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue