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)