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

View file

@ -1,6 +1,17 @@
import logging
from etcd3_wrapper import Etcd3Wrapper
from decouple import config
logging.basicConfig(
level=logging.DEBUG,
filename="log.txt",
filemode="a",
format="%(asctime)s: %(levelname)s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
)
WITHOUT_CEPH = config("WITHOUT_CEPH", False, cast=bool)
etcd_client = Etcd3Wrapper(host=config("ETCD_URL"))

22
log.txt Normal file
View file

@ -0,0 +1,22 @@
05-Sep-19 19:13:22: WARNING - * Debugger is active!
05-Sep-19 19:13:22: INFO - * Debugger PIN: 189-665-873
05-Sep-19 19:13:49: INFO - * Detected change in '/home/meow/Desktop/code/ucloud-api/main.py', reloading
05-Sep-19 19:13:50: WARNING - * Debugger is active!
05-Sep-19 19:13:50: INFO - * Debugger PIN: 189-665-873
05-Sep-19 19:13:57: INFO - * Detected change in '/home/meow/Desktop/code/ucloud-api/main.py', reloading
05-Sep-19 19:13:58: WARNING - * Debugger is active!
05-Sep-19 19:13:58: INFO - * Debugger PIN: 189-665-873
05-Sep-19 19:15:12: INFO - * Detected change in '/home/meow/Desktop/code/ucloud-api/main.py', reloading
05-Sep-19 19:19:39: INFO - * Running on http://[::]:5000/ (Press CTRL+C to quit)
05-Sep-19 19:19:39: INFO - * Restarting with stat
05-Sep-19 19:19:40: WARNING - * Debugger is active!
05-Sep-19 19:19:40: INFO - * Debugger PIN: 189-665-873
05-Sep-19 19:19:43: DEBUG - Starting new HTTPS connection (1): otp.ungleich.ch:443
05-Sep-19 19:19:48: DEBUG - https://otp.ungleich.ch:443 "POST /ungleichotp/verify/ HTTP/1.1" 200 15
05-Sep-19 19:19:48: INFO - ::1 - - [05/Sep/2019 19:19:48] "POST /vm/action HTTP/1.1" 200 -
05-Sep-19 19:19:53: DEBUG - Starting new HTTPS connection (1): otp.ungleich.ch:443
05-Sep-19 19:19:58: DEBUG - https://otp.ungleich.ch:443 "POST /ungleichotp/verify/ HTTP/1.1" 200 15
05-Sep-19 19:19:58: INFO - ::1 - - [05/Sep/2019 19:19:58] "GET /user/vms HTTP/1.1" 200 -
05-Sep-19 19:20:26: DEBUG - Starting new HTTPS connection (1): otp.ungleich.ch:443
05-Sep-19 19:20:32: DEBUG - https://otp.ungleich.ch:443 "POST /ungleichotp/verify/ HTTP/1.1" 200 15
05-Sep-19 19:20:32: INFO - ::1 - - [05/Sep/2019 19:20:32] "POST /vm/action HTTP/1.1" 200 -

11
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,8 +131,13 @@ class VMAction(Resource):
else:
command_to_delete = ["rbd", "rm", path_without_protocol]
subprocess.check_output(command_to_delete)
except Exception as e:
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)