diff --git a/main.py b/main.py index f9dbdde..b4a9043 100644 --- a/main.py +++ b/main.py @@ -196,9 +196,9 @@ class StartVM(Resource): if check_otp(name, realm, token) == 200: vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True) - if vm.value["owner"] != name: - return {"message": "Invalid User"} if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} vm.value["status"] = "REQUESTED_START" client.put(vm.key, json.dumps(vm.value)) return {"message": f"VM Start Queued"} @@ -215,9 +215,9 @@ class SuspendVM(Resource): if check_otp(name, realm, token) == 200: vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True) - if vm.value["owner"] != name: - return {"message": "Invalid User"} if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} vm.value["status"] = "REQUESTED_SUSPEND" client.put(vm.key, json.dumps(vm.value)) return {"message": f"VM Suspension Queued"} @@ -234,9 +234,9 @@ class ResumeVM(Resource): if check_otp(name, realm, token) == 200: vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True) - if vm.value["owner"] != name: - return {"message": "Invalid User"} if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} vm.value["status"] = "REQUESTED_RESUME" client.put(vm.key, json.dumps(vm.value)) return {"message": f"VM Resume Queued"} @@ -253,10 +253,10 @@ class ShutdownVM(Resource): if check_otp(name, realm, token) == 200: vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True) - if vm.value["owner"] != name: - return {"message": "Invalid User"} - if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} + vm.value["status"] = "REQUESTED_SHUTDOWN" client.put(vm.key, json.dumps(vm.value)) return {"message": f"VM Shutdown Queued"}