race condition removed + return message on success updated
This commit is contained in:
parent
55dfda523b
commit
126a3415e5
1 changed files with 4 additions and 2 deletions
4
main.py
4
main.py
|
@ -9,6 +9,7 @@ app = Flask(__name__)
|
|||
api = Api(app)
|
||||
|
||||
etcd_client = etcd.Client(host=config("ETCD_HOST"), port=int(config("ETCD_PORT")))
|
||||
etcd_lock = etcd.Lock(etcd_client, 'etcd_lock')
|
||||
|
||||
createvm_argparser = reqparse.RequestParser()
|
||||
createvm_argparser.add_argument("name", type=str, required=True)
|
||||
|
@ -30,9 +31,10 @@ class CreateVM(Resource):
|
|||
vm_entry = {"owner": name,
|
||||
"specs": specs}
|
||||
|
||||
with etcd_lock:
|
||||
etcd_client.write(f"/v1/vm/{next_vm_id}", vm_entry)
|
||||
|
||||
return {'message': "VM Created"}, 200
|
||||
return {'message': "VM Creation Queued"}, 200
|
||||
else:
|
||||
return {'message': 'Invalid Credentials'}, 400
|
||||
|
||||
|
|
Loading…
Reference in a new issue