check owner of vm after ensuring that vm exists
This commit is contained in:
parent
cdf3c741ee
commit
715128a138
1 changed files with 9 additions and 9 deletions
8
main.py
8
main.py
|
@ -196,9 +196,9 @@ class StartVM(Resource):
|
||||||
|
|
||||||
if check_otp(name, realm, token) == 200:
|
if check_otp(name, realm, token) == 200:
|
||||||
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
||||||
|
if vm:
|
||||||
if vm.value["owner"] != name:
|
if vm.value["owner"] != name:
|
||||||
return {"message": "Invalid User"}
|
return {"message": "Invalid User"}
|
||||||
if vm:
|
|
||||||
vm.value["status"] = "REQUESTED_START"
|
vm.value["status"] = "REQUESTED_START"
|
||||||
client.put(vm.key, json.dumps(vm.value))
|
client.put(vm.key, json.dumps(vm.value))
|
||||||
return {"message": f"VM Start Queued"}
|
return {"message": f"VM Start Queued"}
|
||||||
|
@ -215,9 +215,9 @@ class SuspendVM(Resource):
|
||||||
|
|
||||||
if check_otp(name, realm, token) == 200:
|
if check_otp(name, realm, token) == 200:
|
||||||
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
||||||
|
if vm:
|
||||||
if vm.value["owner"] != name:
|
if vm.value["owner"] != name:
|
||||||
return {"message": "Invalid User"}
|
return {"message": "Invalid User"}
|
||||||
if vm:
|
|
||||||
vm.value["status"] = "REQUESTED_SUSPEND"
|
vm.value["status"] = "REQUESTED_SUSPEND"
|
||||||
client.put(vm.key, json.dumps(vm.value))
|
client.put(vm.key, json.dumps(vm.value))
|
||||||
return {"message": f"VM Suspension Queued"}
|
return {"message": f"VM Suspension Queued"}
|
||||||
|
@ -234,9 +234,9 @@ class ResumeVM(Resource):
|
||||||
|
|
||||||
if check_otp(name, realm, token) == 200:
|
if check_otp(name, realm, token) == 200:
|
||||||
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
||||||
|
if vm:
|
||||||
if vm.value["owner"] != name:
|
if vm.value["owner"] != name:
|
||||||
return {"message": "Invalid User"}
|
return {"message": "Invalid User"}
|
||||||
if vm:
|
|
||||||
vm.value["status"] = "REQUESTED_RESUME"
|
vm.value["status"] = "REQUESTED_RESUME"
|
||||||
client.put(vm.key, json.dumps(vm.value))
|
client.put(vm.key, json.dumps(vm.value))
|
||||||
return {"message": f"VM Resume Queued"}
|
return {"message": f"VM Resume Queued"}
|
||||||
|
@ -253,10 +253,10 @@ class ShutdownVM(Resource):
|
||||||
|
|
||||||
if check_otp(name, realm, token) == 200:
|
if check_otp(name, realm, token) == 200:
|
||||||
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
|
||||||
|
if vm:
|
||||||
if vm.value["owner"] != name:
|
if vm.value["owner"] != name:
|
||||||
return {"message": "Invalid User"}
|
return {"message": "Invalid User"}
|
||||||
|
|
||||||
if vm:
|
|
||||||
vm.value["status"] = "REQUESTED_SHUTDOWN"
|
vm.value["status"] = "REQUESTED_SHUTDOWN"
|
||||||
client.put(vm.key, json.dumps(vm.value))
|
client.put(vm.key, json.dumps(vm.value))
|
||||||
return {"message": f"VM Shutdown Queued"}
|
return {"message": f"VM Shutdown Queued"}
|
||||||
|
|
Loading…
Reference in a new issue