mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 23:01:15 +02:00
Merge branch '2.1' into 2.2
# Conflicts: # gns3server/compute/docker/docker_vm.py # gns3server/controller/compute.py # gns3server/controller/gns3vm/__init__.py # gns3server/controller/link.py # gns3server/controller/project.py # gns3server/handlers/api/controller/project_handler.py # gns3server/handlers/api/controller/server_handler.py # gns3server/utils/asyncio/__init__.py # gns3server/utils/asyncio/telnet_server.py # gns3server/version.py # gns3server/web/web_server.py # tests/compute/qemu/test_qemu_vm.py
This commit is contained in:
commit
33e8710495
43 files changed
+362
-193
No files matched your search
@@ -160,32 +160,32 @@ def wait_for_named_pipe_creation(pipe_path, timeout=60):
|
||||
return
|
||||
raise asyncio.TimeoutError()
|
||||
|
||||
#FIXME: Use the following wrapper when we drop Python 3.4 and use the async def syntax
|
||||
# def locking(f):
|
||||
#
|
||||
# @wraps(f)
|
||||
# async def wrapper(oself, *args, **kwargs):
|
||||
# lock_name = "__" + f.__name__ + "_lock"
|
||||
# if not hasattr(oself, lock_name):
|
||||
# setattr(oself, lock_name, asyncio.Lock())
|
||||
# async with getattr(oself, lock_name):
|
||||
# return await f(oself, *args, **kwargs)
|
||||
# return wrapper
|
||||
|
||||
def locked_coroutine(f):
|
||||
"""
|
||||
Method decorator that replace asyncio.coroutine that guarantee
|
||||
that this specific method of this class instance will not be
|
||||
executed twice at the same time
|
||||
"""
|
||||
@asyncio.coroutine
|
||||
def new_function(*args, **kwargs):
|
||||
def locking(f):
|
||||
|
||||
# In the instance of the class we will store
|
||||
# a lock has an attribute.
|
||||
lock_var_name = "__" + f.__name__ + "_lock"
|
||||
if not hasattr(args[0], lock_var_name):
|
||||
setattr(args[0], lock_var_name, asyncio.Lock())
|
||||
@functools.wraps(f)
|
||||
def wrapper(oself, *args, **kwargs):
|
||||
lock_name = "__" + f.__name__ + "_lock"
|
||||
if not hasattr(oself, lock_name):
|
||||
setattr(oself, lock_name, asyncio.Lock())
|
||||
with (yield from getattr(oself, lock_name)):
|
||||
return (yield from f(oself, *args, **kwargs))
|
||||
return wrapper
|
||||
|
||||
with (yield from getattr(args[0], lock_var_name)):
|
||||
return (yield from f(*args, **kwargs))
|
||||
|
||||
return new_function
|
||||
|
||||
|
||||
# It's conservative approach to supported versions, please remove it when we drop the support to Python < 3.4.4
|
||||
if hasattr(asyncio, 'ensure_future'):
|
||||
# python>=3.4.4
|
||||
#FIXME: conservative approach to supported versions, please remove it when we drop the support to Python < 3.4.4
|
||||
try:
|
||||
from asyncio import ensure_future
|
||||
asyncio_ensure_future = asyncio.ensure_future
|
||||
else:
|
||||
# deprecated
|
||||
asyncio_ensure_future = asyncio.async
|
||||
except ImportError:
|
||||
asyncio_ensure_future = getattr(asyncio, 'async')
|
||||
@@ -214,9 +214,12 @@ class AsyncioTelnetServer:
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
for writer, connection in self._connections.items():
|
||||
writer.write_eof()
|
||||
yield from writer.drain()
|
||||
|
||||
try:
|
||||
writer.write_eof()
|
||||
yield from writer.drain()
|
||||
except ConnectionResetError:
|
||||
continue
|
||||
|
||||
@asyncio.coroutine
|
||||
def client_connected_hook(self):
|
||||
pass
|
||||
@@ -319,6 +322,7 @@ class AsyncioTelnetServer:
|
||||
else:
|
||||
log.debug("Not supported negotiation sequence, received {} bytes", len(data))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _IAC_parser(self, buf, network_reader, network_writer, connection):
|
||||
"""
|
||||
Processes and removes any Telnet commands from the buffer.
|
||||
@@ -421,9 +425,9 @@ if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
process = loop.run_until_complete(asyncio_ensure_future(asyncio.subprocess.create_subprocess_exec("/bin/sh", "-i",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT,
|
||||
stdin=asyncio.subprocess.PIPE)))
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT,
|
||||
stdin=asyncio.subprocess.PIPE)))
|
||||
server = AsyncioTelnetServer(reader=process.stdout, writer=process.stdin, binary=False, echo=False)
|
||||
|
||||
coro = asyncio.start_server(server.run, '127.0.0.1', 4444, loop=loop)
|
||||
|
||||
Reference in new issue
Block a user