mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
VM concurrency
This commit is contained in:
parent
9153b42b9d
commit
46b348e46a
@ -20,6 +20,8 @@ from ...schemas.version import VERSION_SCHEMA
|
||||
from ...version import __version__
|
||||
from aiohttp.web import HTTPConflict
|
||||
|
||||
import asyncio
|
||||
|
||||
|
||||
class VersionHandler:
|
||||
|
||||
@ -45,3 +47,12 @@ class VersionHandler:
|
||||
if request.json["version"] != __version__:
|
||||
raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"], __version__))
|
||||
response.json({"version": __version__})
|
||||
|
||||
@staticmethod
|
||||
@Route.get(
|
||||
r"/sleep/{vm_id}",
|
||||
description="Retrieve the server version number",
|
||||
output=VERSION_SCHEMA)
|
||||
def sleep(request, response):
|
||||
yield from asyncio.sleep(1)
|
||||
response.json({"version": __version__})
|
||||
|
@ -63,6 +63,8 @@ class Route(object):
|
||||
_routes = []
|
||||
_documentation = {}
|
||||
|
||||
_vms_lock = {}
|
||||
|
||||
@classmethod
|
||||
def get(cls, path, *args, **kw):
|
||||
return cls._route('GET', path, *args, **kw)
|
||||
@ -150,9 +152,22 @@ class Route(object):
|
||||
|
||||
return response
|
||||
|
||||
cls._routes.append((method, cls._path, control_schema))
|
||||
@asyncio.coroutine
|
||||
def vm_concurrency(request):
|
||||
"""
|
||||
To avoid strange effect we prevent concurrency
|
||||
between the same instance of the vm
|
||||
"""
|
||||
|
||||
return control_schema
|
||||
if "vm_id" in request.match_info:
|
||||
cls._vms_lock.setdefault(request.match_info["vm_id"], asyncio.Lock())
|
||||
with (yield from cls._vms_lock[request.match_info["vm_id"]]):
|
||||
response = yield from control_schema(request)
|
||||
return response
|
||||
|
||||
cls._routes.append((method, cls._path, vm_concurrency))
|
||||
|
||||
return vm_concurrency
|
||||
return register
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user