Skip to content

Commit

Permalink
Drop IOUCON
Browse files Browse the repository at this point in the history
Fix #747
  • Loading branch information
julien-duponchelle committed Nov 8, 2016
1 parent 15d190d commit 3754a49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 714 deletions.
54 changes: 19 additions & 35 deletions gns3server/compute/iou/iou_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
from ..base_node import BaseNode
from .utils.iou_import import nvram_import
from .utils.iou_export import nvram_export
from .ioucon import start_ioucon
from gns3server.ubridge.ubridge_error import UbridgeError
from gns3server.utils.file_watcher import FileWatcher
from gns3server.utils.asyncio.telnet_server import AsyncioTelnetServer
import gns3server.utils.asyncio
import gns3server.utils.images

Expand All @@ -71,10 +71,10 @@ def __init__(self, name, node_id, project, manager, console=None):
super().__init__(name, node_id, project, manager, console=console)

self._iou_process = None
self._telnet_server = None
self._iou_stdout_file = ""
self._started = False
self._path = None
self._ioucon_thread = None
self._nvram_watcher = None

# IOU settings
Expand Down Expand Up @@ -485,15 +485,14 @@ def start(self):
command = yield from self._build_command()
try:
log.info("Starting IOU: {}".format(command))
self._iou_stdout_file = os.path.join(self.working_dir, "iou.log")
log.info("Logging to {}".format(self._iou_stdout_file))
with open(self._iou_stdout_file, "w", encoding="utf-8") as fd:
self.command_line = ' '.join(command)
self._iou_process = yield from asyncio.create_subprocess_exec(*command,
stdout=fd,
stderr=subprocess.STDOUT,
cwd=self.working_dir,
env=env)
self.command_line = ' '.join(command)
self._iou_process = yield from asyncio.create_subprocess_exec(
*command,
stdout=asyncio.subprocess.PIPE,
stdin=asyncio.subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=self.working_dir,
env=env)
log.info("IOU instance {} started PID={}".format(self._id, self._iou_process.pid))
self._started = True
self.status = "started"
Expand All @@ -506,8 +505,8 @@ def start(self):
log.error("Could not start IOU {}: {}\n{}".format(self._path, e, iou_stdout))
raise IOUError("Could not start IOU {}: {}\n{}".format(self._path, e, iou_stdout))

# start console support
self._start_ioucon()
server = AsyncioTelnetServer(reader=self._iou_process.stdout, writer=self._iou_process.stdin, binary=True, echo=True)
self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)

# configure networking support
yield from self._networking()
Expand Down Expand Up @@ -557,7 +556,6 @@ def _termination_callback(self, process_name, returncode):
"""

self._terminate_process_iou()
self._ioucon_thread_stop_event.set()

if returncode != 0:
if returncode == 11:
Expand All @@ -566,6 +564,9 @@ def _termination_callback(self, process_name, returncode):
message = "{} process has stopped, return code: {}\n{}".format(process_name, returncode, self.read_iou_stdout())
log.warn(message)
self.project.emit("log.error", {"message": message})
if self._telnet_server:
self._telnet_server.close()
self._telnet_server = None

def _rename_nvram_file(self):
"""
Expand All @@ -590,14 +591,11 @@ def stop(self):
self._nvram_watcher.close()
self._nvram_watcher = None

if self.is_running():
# stop console support
if self._ioucon_thread:
self._ioucon_thread_stop_event.set()
if self._ioucon_thread.is_alive():
self._ioucon_thread.join(timeout=3.0) # wait for the thread to free the console port
self._ioucon_thread = None
if self._telnet_server:
self._telnet_server.close()
self._telnet_server = None

if self.is_running():
self._terminate_process_iou()
if self._iou_process.returncode is None:
try:
Expand Down Expand Up @@ -707,7 +705,6 @@ def _build_command(self):
if not self.use_default_iou_values:
command.extend(["-n", str(self._nvram)])
command.extend(["-m", str(self._ram)])
command.extend(["-L"]) # disable local console, use remote console

# do not let IOU create the NVRAM anymore
#startup_config_file = self.startup_config_file
Expand All @@ -734,19 +731,6 @@ def read_iou_stdout(self):
log.warn("could not read {}: {}".format(self._iou_stdout_file, e))
return output

def _start_ioucon(self):
"""
Starts ioucon thread (for console connections).
"""

if not self._ioucon_thread:
telnet_server = "{}:{}".format(self._manager.port_manager.console_host, self.console)
log.info("Starting ioucon for IOU instance {} to accept Telnet connections on {}".format(self._name, telnet_server))
args = argparse.Namespace(appl_id=str(self.application_id), debug=False, escape='^^', telnet_limit=0, telnet_server=telnet_server)
self._ioucon_thread_stop_event = threading.Event()
self._ioucon_thread = threading.Thread(target=start_ioucon, args=(args, self._ioucon_thread_stop_event))
self._ioucon_thread.start()

@property
def ethernet_adapters(self):
"""
Expand Down
Loading

0 comments on commit 3754a49

Please sign in to comment.