[pve-devel] [PATCH manager 1/4] allow xtermjs to be the default console

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Apr 20 10:50:22 CEST 2018


On 4/13/18 9:49 AM, Dominik Csapak wrote:
> if not available for a vm, we fallback to novnc like with spice
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  www/manager6/Utils.js                | 40 ++++++++++++++++++++++++------------
>  www/manager6/button/ConsoleButton.js |  6 +++++-
>  www/manager6/qemu/CmdMenu.js         |  7 ++++++-
>  3 files changed, 38 insertions(+), 15 deletions(-)
> 
> diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
> index af03958c..6163c2e6 100644
> --- a/www/manager6/Utils.js
> +++ b/www/manager6/Utils.js
> @@ -279,19 +279,23 @@ Ext.define('PVE.Utils', { utilities: {
>      },
>  
>      render_console_viewer: function(value) {
> -	if (!value || value === '__default__') {
> -	    return Proxmox.Utils.defaultText + ' (HTML5)';
> -	} else if (value === 'vv') {
> -	    return  'SPICE (remote-viewer)';
> -	} else if (value === 'html5') {
> -	    return  'HTML5 (noVNC)';
> -	} else {
> -	    return value;
> +	value = value || '__default__';
> +	switch (value) {
> +	    case 'vv':
> +		return  'SPICE (remote-viewer)';
> +	    case 'html5':
> +		return  'HTML5 (noVNC)';
> +	    case 'xtermjs':
> +		return 'xterm.js';
> +	    case '__default__':
> +		return Proxmox.Utils.defaultText + ' (HTML5)';
> +	    default:
> +		return value;

maybe use an mapping here?

consoleMap = {
   vv: 'SPICE (remote-viewer)'
   ...
},

and a simple if (in map) return mapping; else return value;
you could then reuse this below...

>  	}
>      },
>  
>      console_viewer_array: function() {
> -	return Ext.Array.map(['__default__','vv', 'html5'], function(v) {
> +	return Ext.Array.map(['__default__','vv', 'html5', 'xtermjs'], function(v) {

... here, with Object.keys(consoleMap), for less duplication.
Could be done afterwards but as you already touch all this
here... :)

>  	    return [v, PVE.Utils.render_console_viewer(v)];
>  	});
>      },
> @@ -723,8 +727,8 @@ Ext.define('PVE.Utils', { utilities: {
>              function(m, addr, offset, original) { return addr; });
>      },
>  
> -    openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) {
> -	var dv = PVE.Utils.defaultViewer(allowSpice);
> +    openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname) {
> +	var dv = PVE.Utils.defaultViewer(consoles);
>  	PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname);
>      },
>  
> @@ -765,10 +769,20 @@ Ext.define('PVE.Utils', { utilities: {
>  	}
>      },
>  
> -    defaultViewer: function(allowSpice) {
> +    defaultViewer: function(consoles) {
> +
> +	var allowSpice, allowXtermjs;
> +
> +	if (consoles === true) {
> +	    allowSpice = true;
> +	    allowXtermjs = true;
> +	} else if (typeof consoles === 'object') {
> +	    allowSpice = consoles.spice;
> +	    allowXtermjs = consoles.xtermjs;
> +	}
>  	var vncdefault = 'html5';
>  	var dv = PVE.VersionInfo.console || vncdefault;
> -	if (dv === 'vv' && !allowSpice) {
> +	if ((dv === 'vv' && !allowSpice) || (dv === 'xtermjs' && !allowXtermjs)) {
>  	    dv = vncdefault;
>  	}
>  
> diff --git a/www/manager6/button/ConsoleButton.js b/www/manager6/button/ConsoleButton.js
> index 97bed170..d825e1fb 100644
> --- a/www/manager6/button/ConsoleButton.js
> +++ b/www/manager6/button/ConsoleButton.js
> @@ -33,7 +33,11 @@ Ext.define('PVE.button.ConsoleButton', {
>  
>      handler: function() {
>  	var me = this;
> -	PVE.Utils.openDefaultConsoleWindow(me.enableSpice, me.consoleType, me.vmid,
> +	var consoles = {
> +	    spice: me.enableSpice,
> +	    xtermjs: me.enableXtermjs
> +	};
> +	PVE.Utils.openDefaultConsoleWindow(consoles, me.consoleType, me.vmid,
>  					   me.nodename, me.consoleName);
>      },
>  
> diff --git a/www/manager6/qemu/CmdMenu.js b/www/manager6/qemu/CmdMenu.js
> index 00af7cbc..da6f556a 100644
> --- a/www/manager6/qemu/CmdMenu.js
> +++ b/www/manager6/qemu/CmdMenu.js
> @@ -169,7 +169,12 @@ Ext.define('PVE.qemu.CmdMenu', {
>  			},
>  			success: function(response, opts) {
>  			    var allowSpice = response.result.data.spice;
> -			    PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
> +			    var allowXtermjs = response.result.data.serial;
> +			    var consoles = {
> +				spice: allowSpice,
> +				xtermjs: allowXtermjs
> +			    };
> +			    PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
>  			}
>  		    });
>  		}
> 





More information about the pve-devel mailing list