mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Endpoint for obtaining direct action on compute
This commit is contained in:
1 parent
e52b83be11
commit
b654d78ea6
5 files changed
+69
-1
No files matched your search
@@ -477,6 +477,10 @@ class Compute:
|
||||
host = "127.0.0.1"
|
||||
return "{}://{}:{}/v2/compute{}".format(self._protocol, host, self._port, path)
|
||||
|
||||
def get_url(self, path):
|
||||
""" Returns URL for specific path at Compute"""
|
||||
return self._getUrl(path)
|
||||
|
||||
@asyncio.coroutine
|
||||
def _run_http_query(self, method, path, data=None, timeout=20, raw=False):
|
||||
with Timeout(timeout):
|
||||
|
||||
@@ -21,7 +21,8 @@ from gns3server.controller import Controller
|
||||
from gns3server.schemas.compute import (
|
||||
COMPUTE_CREATE_SCHEMA,
|
||||
COMPUTE_OBJECT_SCHEMA,
|
||||
COMPUTE_UPDATE_SCHEMA
|
||||
COMPUTE_UPDATE_SCHEMA,
|
||||
COMPUTE_ENDPOINT_OUTPUT_OBJECT_SCHEMA
|
||||
)
|
||||
|
||||
import logging
|
||||
@@ -93,6 +94,33 @@ class ComputeHandler:
|
||||
res = yield from compute.images(request.match_info["emulator"])
|
||||
response.json(res)
|
||||
|
||||
@Route.get(
|
||||
r"/computes/endpoint/{compute_id}/{emulator}/{action:.+}",
|
||||
parameters={
|
||||
"compute_id": "Compute UUID"
|
||||
},
|
||||
status_codes={
|
||||
200: "OK",
|
||||
404: "Instance doesn't exist"
|
||||
},
|
||||
raw=True,
|
||||
output=COMPUTE_ENDPOINT_OUTPUT_OBJECT_SCHEMA,
|
||||
description="Returns the endpoint for particular `compute` to specific action.")
|
||||
def endpoint(request, response):
|
||||
controller = Controller.instance()
|
||||
compute = controller.get_compute(request.match_info["compute_id"])
|
||||
|
||||
path = '/{emulator}/{action}'.format(
|
||||
emulator=request.match_info['emulator'],
|
||||
action=request.match_info['action'])
|
||||
|
||||
endpoint = compute.get_url(path)
|
||||
|
||||
response.set_status(200)
|
||||
response.json(dict(
|
||||
endpoint=endpoint
|
||||
))
|
||||
|
||||
@Route.get(
|
||||
r"/computes/{compute_id}/{emulator}/{action:.+}",
|
||||
parameters={
|
||||
|
||||
@@ -109,3 +109,17 @@ COMPUTE_OBJECT_SCHEMA = {
|
||||
"additionalProperties": False,
|
||||
"required": ["compute_id", "protocol", "host", "port", "name"]
|
||||
}
|
||||
|
||||
COMPUTE_ENDPOINT_OUTPUT_OBJECT_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Output schema for obtaining endpoint on compute",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"endpoint": {
|
||||
"description": "URL to endpoint on specific compute and to particular action",
|
||||
"type": "string"
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user