From 50e0dc8d1f7dd1c600f2945de356f8e817160c9d Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 2 Jan 2023 19:42:23 +0100 Subject: [PATCH] implemented '/leasing/v1/lessor/shutdown' for windows guests --- app/main.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/main.py b/app/main.py index d4da9f4..02fe569 100644 --- a/app/main.py +++ b/app/main.py @@ -487,6 +487,28 @@ async def leasing_v1_lessor_lease_remove(request: Request): return JSONResponse(response) +@app.post('/leasing/v1/lessor/shutdown', description='shutdown all leases') +async def leasing_v1_lessor_shutdown(request: Request): + j, cur_time = json.loads((await request.body()).decode('utf-8')) + + token = j['token'] + token = jwt.decode(token=token, key=jwt_decode_key, algorithms=ALGORITHMS.RS256, options={'verify_aud': False}) + origin_ref = token.get('origin_ref') + + released_lease_list = list(map(lambda x: x.lease_ref, Lease.find_by_origin_ref(db, origin_ref))) + deletions = Lease.cleanup(db, origin_ref) + logging.info(f'> [ shutdown ]: {origin_ref}: removed {deletions} leases') + + response = { + "released_lease_list": released_lease_list, + "release_failure_list": None, + "sync_timestamp": cur_time.isoformat(), + "prompts": None + } + + return JSONResponse(response) + + if __name__ == '__main__': import uvicorn