Get the Serial over LAN console working
This commit hooks up hterm to a websocket that the BMC's REST server
exposes as an access to the host serial console. Writes to the terminal
are sent over the websocket and reads from the websocket are written to
the terminal.
The websocket is open only when the console page in the GUI is loaded.
Tested:
- The host console can be accessed as expected from the GUI page.
- The "Open in new tab" is still unimplemented. I'll code that up in a
subsequent commit.
- One issue that I've noticed is if you have the console open before the
host is powered on, and then you power on the host, at the time the
petitboot config menu shows, the text in the terminal stops scrolling
and starts wrapping. The work-around is to refresh the page. This
doesn't happen for example if you access the console after the host
has powered on, or at any other time for that matter. I think this is
an hterm.js issue. I'm still investigating.
- The console looks desirably performant. The REST server's performance
to serve other routes is not impacted when the /console websocket is
open.
Change-Id: I35fa39d7f63094552061b097c46be0fda79ed14f
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/app/server-control/controllers/remote-console-controller.js b/app/server-control/controllers/remote-console-controller.js
index d20115e..ee6a591 100644
--- a/app/server-control/controllers/remote-console-controller.js
+++ b/app/server-control/controllers/remote-console-controller.js
@@ -23,35 +23,48 @@
// See https://github.com/macton/hterm for available hterm options
- //Storage
hterm.defaultStorage = new lib.Storage.Local();
+ var term = new hterm.Terminal("host-console");
+ term.decorate(document.querySelector('#terminal'));
+ //Set cursor color
+ term.prefs_.set('cursor-color', 'rgba(83, 146, 255, .5)');
+ //Set background color
+ term.prefs_.set('background-color', '#19273c');
+ //Allows keyboard input
+ term.installKeyboard();
- var term = new hterm.Terminal("foo");
+ //The BMC exposes a websocket at /console0. This can be read
+ //or written to access the host serial console.
+ var hostname = dataService.getHost().replace("https://", '');
+ var host = "wss://" + hostname + "/console0";
+ var ws = new WebSocket(host);
+ ws.onmessage = function (evt) {
+ //websocket -> terminal
+ term.io.print(evt.data);
+ };
+
+ //terminal -> websocket
term.onTerminalReady = function() {
var io = term.io.push();
io.onVTKeystroke = function(str) {
- console.log(str)
- term.io.print(str);
+ ws.send(str);
};
io.sendString = function(str) {
- console.log(str)
+ ws.send(str);
};
};
- term.decorate(document.querySelector('#terminal'));
- //Set cursor color
- term.prefs_.set('cursor-color', 'rgba(83, 146, 255, .5)');
-
- //Set background color
- term.prefs_.set('background-color', '#19273c');
-
- //Print to console window
- term.io.println('OpenBMC ver.00');
- term.io.println('This is not an actual live connection.');
- term.io.print('root@OpenBmc:');
-
- //Allows keyboard input
- term.installKeyboard();
+ ws.onopen = function() {
+ console.log("websocket opened");
+ };
+ ws.onclose = function() {
+ console.log("websocket closed");
+ };
+ $scope.$on("$destroy", function() {
+ if(ws) {
+ ws.close();
+ }
+ });
$scope.openTerminalWindow = function(){
dataService.setRemoteWindowActive();