1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Add api versionning

This commit is contained in:
Julien Duponchelle 2015-02-04 10:24:59 +01:00
parent 119bebee25
commit 08158884a4
3 changed files with 5 additions and 4 deletions

View File

@ -84,7 +84,8 @@ class Route(object):
# This block is executed only the first time
output_schema = kw.get("output", {})
input_schema = kw.get("input", {})
cls._path = path
api_version = kw.get("version", 1)
cls._path = "/v{version}{path}".format(path=path, version=api_version)
cls._documentation.setdefault(cls._path, {"methods": []})
def register(func):

View File

@ -45,7 +45,7 @@ class Query:
return self._fetch("DELETE", path, **kwargs)
def _get_url(self, path):
return "http://{}:{}{}".format(self._host, self._port, path)
return "http://{}:{}/v1{}".format(self._host, self._port, path)
def _fetch(self, method, path, body=None, **kwargs):
"""Fetch an url, parse the JSON and return response
@ -74,7 +74,7 @@ class Query:
asyncio.async(go(future, response))
self._loop.run_until_complete(future)
response.body = future.result()
response.route = response.headers.get('X-Route', None)
response.route = response.headers.get('X-Route', None).replace("/v1", "")
if response.body is not None:
try:

View File

@ -10,4 +10,4 @@ ignore = E501
[pytest]
norecursedirs = old_tests .tox
timeout = 10
timeout = 1