From 77741f363d220ab6717416f7f33149d0f52e5d8a Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Khalid Date: Tue, 25 Jun 2019 15:07:23 +0500 Subject: [PATCH] endpoint (/vm/status) created to dump vm status --- main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.py b/main.py index 8a619b9..5724b32 100644 --- a/main.py +++ b/main.py @@ -19,6 +19,9 @@ createvm_argparser.add_argument("realm", type=str, required=True) createvm_argparser.add_argument("seed", type=str, required=True) createvm_argparser.add_argument("specs", type=dict, required=True) +vmstatus_argparser = reqparse.RequestParser() +vmstatus_argparser.add_argument("id", type=str, required=True) + class CreateVM(Resource): def post(self): @@ -31,6 +34,7 @@ class CreateVM(Resource): vm_entry = {"owner": name, "specs": specs, + "hostname": "", "status": VmStatus.REQUESTED_NEW.value} etcd_client.put(f"/v1/vm/{uuid4().hex}", json.dumps(vm_entry)) @@ -40,7 +44,18 @@ class CreateVM(Resource): return {'message': 'Invalid Credentials'}, 400 +class VmStatus(Resource): + def get(self): + args = vmstatus_argparser.parse_args() + r = etcd_client.get(f"/v1/vm/{args.id}")[0] + if r: + r = dict(json.loads(r.decode("utf-8"))) + return r + return {"Message": "Not Found"} + + api.add_resource(CreateVM, '/vm/create') +api.add_resource(VmStatus, '/vm/status') if __name__ == '__main__': app.run(debug=True)