diff --git a/main.py b/main.py index fe69e11..2c0086f 100644 --- a/main.py +++ b/main.py @@ -33,6 +33,20 @@ class VM: vm: qmp.QEMUMachine +class RBD(object): + @staticmethod + def ls(pool): + output = "" + try: + output = subprocess.check_output( + ["rbd", "ls", pool], stderr=subprocess.PIPE + ).decode("utf-8").strip() + except subprocess.CalledProcessError as e: + raise Exception(e.stderr) + return output.split("\n") + + + logging.basicConfig( level=logging.DEBUG, filename="log.txt", @@ -99,12 +113,13 @@ def start_vm(vm_path, e): # uservms pool then checkwhether the e.key.split("/").pop() # exists in rbd_ls(uservms_pool) - # if not os.path.isfile(vm_path): - # logging.info(f"Image file of vm {e.key} does not exists") - # logging.info(f"Setting vm {e.key} status to DELETED") - # e.value["status"] = "DELETED" - # client.put(e.key, json.dumps(e.value)) - # return + if not vm_path.split("/")[-1] in RBD.ls("uservms") + logging.info(f"Image file of vm {e.key} does not exists") + logging.info(f"Setting vm {e.key} status to DELETED") + e.value["status"] = "DELETED" + client.put(e.key, json.dumps(e.value)) + return + _vm = get_vm(running_vms, e.key) if _vm: