-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Support for serial console for Virtual BOX
Ref #747
- Loading branch information
1 parent
3e0854e
commit 9b273d7
Showing
4 changed files
with
98 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright (C) 2016 GNS3 Technologies Inc. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import sys | ||
import asyncio | ||
from gns3server.utils.asyncio import wait_for_file_creation, wait_for_named_pipe_creation | ||
from gns3server.compute.error import NodeError | ||
|
||
""" | ||
This module handle connection to unix socket or Windows named pipe | ||
""" | ||
|
||
|
||
class SerialReaderWriterProtocol(asyncio.Protocol): | ||
|
||
def __init__(self): | ||
self._output = asyncio.StreamReader() | ||
self.transport = None | ||
|
||
def read(self, n=-1): | ||
return self._output.read(n=n) | ||
|
||
def at_eof(self): | ||
return self._output.at_eof() | ||
|
||
def write(self, data): | ||
if self.transport: | ||
self.transport.write(data) | ||
|
||
@asyncio.coroutine | ||
def drain(self): | ||
pass | ||
|
||
def connection_made(self, transport): | ||
self.transport = transport | ||
|
||
def data_received(self, data): | ||
self._output.feed_data(data) | ||
|
||
#TODO: Manage CLOSE cleanup the pipe | ||
|
||
|
||
@asyncio.coroutine | ||
def asyncio_open_serial(path): | ||
""" | ||
Open a unix socket or a windows named pipe | ||
:returns: An IO like object | ||
""" | ||
|
||
try: | ||
# wait for VM to create the pipe file. | ||
if sys.platform.startswith("win"): | ||
yield from wait_for_named_pipe_creation(path) | ||
else: | ||
yield from wait_for_file_creation(path) | ||
except asyncio.TimeoutError: | ||
raise NodeError('Pipe file "{}" is missing'.format(path)) | ||
|
||
output = SerialReaderWriterProtocol() | ||
con = yield from asyncio.get_event_loop().create_unix_connection(lambda: output, path) | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters