mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
5 files changed
+167
-4
No files matched your search
@@ -33,6 +33,7 @@ from ..base_vm import BaseVM
|
||||
from ..adapters.ethernet_adapter import EthernetAdapter
|
||||
from ..nios.nio_udp import NIOUDP
|
||||
from ...utils.asyncio.telnet_server import AsyncioTelnetServer
|
||||
from ...utils.asyncio.raw_command_server import AsyncioRawCommandServer
|
||||
from ...utils.asyncio import wait_for_file_creation
|
||||
from ...utils.get_resource import get_resource
|
||||
from ...ubridge.ubridge_error import UbridgeError, UbridgeNamespaceError
|
||||
@@ -54,12 +55,14 @@ class DockerVM(BaseVM):
|
||||
:param console_type: Console type
|
||||
:param aux: TCP aux console port
|
||||
:param console_resolution: Resolution of the VNC display
|
||||
:param console_http_port: Port to redirect HTTP queries
|
||||
:param console_http_path: Url part with the path of the web interface
|
||||
"""
|
||||
|
||||
def __init__(self, name, vm_id, project, manager, image,
|
||||
console=None, aux=None, start_command=None,
|
||||
adapters=None, environment=None, console_type="telnet",
|
||||
console_resolution="1024x768"):
|
||||
console_resolution="1024x768", console_http_port=80, console_http_path="/"):
|
||||
super().__init__(name, vm_id, project, manager, console=console, aux=aux, allocate_aux=True, console_type=console_type)
|
||||
|
||||
self._image = image
|
||||
@@ -72,6 +75,8 @@ class DockerVM(BaseVM):
|
||||
self._telnet_servers = []
|
||||
self._x11vnc_process = None
|
||||
self._console_resolution = console_resolution
|
||||
self._console_http_path = console_http_path
|
||||
self._console_http_port = console_http_port
|
||||
|
||||
if adapters is None:
|
||||
self.adapters = 1
|
||||
@@ -95,6 +100,8 @@ class DockerVM(BaseVM):
|
||||
"console": self.console,
|
||||
"console_type": self.console_type,
|
||||
"console_resolution": self.console_resolution,
|
||||
"console_http_port": self.console_http_port,
|
||||
"console_http_path": self.console_http_path,
|
||||
"aux": self.aux,
|
||||
"start_command": self.start_command,
|
||||
"environment": self.environment,
|
||||
@@ -133,6 +140,22 @@ class DockerVM(BaseVM):
|
||||
def console_resolution(self, resolution):
|
||||
self._console_resolution = resolution
|
||||
|
||||
@property
|
||||
def console_http_path(self):
|
||||
return self._console_http_path
|
||||
|
||||
@console_http_path.setter
|
||||
def console_http_path(self, path):
|
||||
self._console_http_path = path
|
||||
|
||||
@property
|
||||
def console_http_port(self):
|
||||
return self._console_http_port
|
||||
|
||||
@console_http_port.setter
|
||||
def console_http_port(self, port):
|
||||
self._console_http_port = port
|
||||
|
||||
@property
|
||||
def environment(self):
|
||||
return self._environment
|
||||
@@ -322,6 +345,8 @@ class DockerVM(BaseVM):
|
||||
|
||||
if self.console_type == "telnet":
|
||||
yield from self._start_console()
|
||||
elif self.console_type == "http" or self.console_type == "https":
|
||||
yield from self._start_http()
|
||||
|
||||
if self.allocate_aux:
|
||||
yield from self._start_aux()
|
||||
@@ -361,11 +386,22 @@ class DockerVM(BaseVM):
|
||||
x11_socket = os.path.join("/tmp/.X11-unix/", "X{}".format(self._display))
|
||||
yield from wait_for_file_creation(x11_socket)
|
||||
|
||||
@asyncio.coroutine
|
||||
def _start_http(self):
|
||||
"""
|
||||
Start an HTTP tunnel to container localhost
|
||||
"""
|
||||
log.debug("Forward HTTP for %s to %d", self.name, self._console_http_port)
|
||||
command = ["docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "nc", "127.0.0.1", str(self._console_http_port)]
|
||||
server = AsyncioRawCommandServer(command)
|
||||
self._telnet_servers.append((yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _start_console(self):
|
||||
"""
|
||||
Start streaming the console via telnet
|
||||
"""
|
||||
|
||||
class InputStream:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
Reference in new issue
Block a user