Support forwarding POST request to compute nodes

This commit is contained in:
Julien Duponchelle committed 2016-06-06 15:45:32 +02:00
1 parent 61ac8763f2
commit 06b54d82dc
4 files changed
+51 -8

No files matched your search

+2 -2
View File
@@ -324,9 +324,9 @@ class Compute:
return (yield from self.http_query("DELETE", path, **kwargs))
@asyncio.coroutine
def forward(self, type, path):
def forward(self, method, type, path, data=None):
"""
Forward a call to the emulator on compute
"""
res = yield from self.get("/{}/{}".format(type, path))
res = yield from self.http_query(method, "/{}/{}".format(type, path), data=data)
return res.json
@@ -87,10 +87,26 @@ class ComputeHandler:
404: "Instance doesn't exist"
},
description="Forward call specific to compute node. Read the full compute API for available actions")
def forward(request, response):
def get_forward(request, response):
controller = Controller.instance()
compute = controller.get_compute(request.match_info["compute_id"])
images = yield from compute.forward(request.match_info["emulator"], request.match_info["action"])
images = yield from compute.forward("GET", request.match_info["emulator"], request.match_info["action"])
response.json(images)
@Route.post(
r"/computes/{compute_id}/{emulator}/{action}",
parameters={
"compute_id": "Compute UUID"
},
status_codes={
200: "OK",
404: "Instance doesn't exist"
},
description="Forward call specific to compute node. Read the full compute API for available actions")
def post_forward(request, response):
controller = Controller.instance()
compute = controller.get_compute(request.match_info["compute_id"])
images = yield from compute.forward("POST", request.match_info["emulator"], request.match_info["action"], data=dict(request.json))
response.json(images)
@Route.get(