[pve-devel] r5962 - in pve-manager/pve2/www/new: . qemu

svn-commits at proxmox.com svn-commits at proxmox.com
Wed May 11 13:00:48 CEST 2011


Author: dietmar
Date: 2011-05-11 13:00:48 +0200 (Wed, 11 May 2011)
New Revision: 5962

Added:
   pve-manager/pve2/www/new/VNCConsole.js
Modified:
   pve-manager/pve2/www/new/Makefile.am
   pve-manager/pve2/www/new/index.pl
   pve-manager/pve2/www/new/qemu/Config.js
Log:
impl. console


Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am	2011-05-11 09:36:18 UTC (rev 5961)
+++ pve-manager/pve2/www/new/Makefile.am	2011-05-11 11:00:48 UTC (rev 5962)
@@ -3,6 +3,7 @@
 JSSRC= 				                 	\
 	PVEUtils.js					\
 	StateProvider.js				\
+	VNCConsole.js					\
 	data/TimezoneStore.js				\
 	data/reader/JsonObject.js			\
 	data/PVEProxy.js				\

Added: pve-manager/pve2/www/new/VNCConsole.js
===================================================================
--- pve-manager/pve2/www/new/VNCConsole.js	                        (rev 0)
+++ pve-manager/pve2/www/new/VNCConsole.js	2011-05-11 11:00:48 UTC (rev 5962)
@@ -0,0 +1,285 @@
+PVE_vnc_console_event = function(appletid, action, err) {
+    //console.log("TESTINIT param1 " + appletid + " action " + action);
+
+    return;
+
+    var el = Ext.get(appletid);
+    if (!el)
+	return;
+
+    if (action === "close") {
+//	el.remove();
+    } else if (action === "error") {
+//	console.log("TESTERROR: " + err);
+//	var compid = appletid.replace("-vncapp", "");
+//	var comp = Ext.getCmp(compid);
+    }
+
+    //Ext.get('mytestid').remove();
+};
+
+Ext.define('PVE.VNCConsole', {
+    extend: 'Ext.panel.Panel',
+    alias: ['widget.pveVNCConsole'],
+
+    initComponent : function() {
+	var me = this;
+
+	if (!me.url) 
+	    throw "no url specified";
+
+	var myid = me.id + "-vncapp";
+
+	me.appletID = myid;
+
+	var box = Ext.create('Ext.Component', {
+	    border: false,
+	    html: ""
+	});
+
+	var resize_window = function() {
+	    //console.log("resize");
+
+	    var applet = Ext.getDom(myid);
+	    //console.log("resize " + myid + " " + applet);
+	    
+	    // try again when dom element is available
+	    if (!(applet && Ext.isFunction(applet.getPreferredSize))) 
+		return Ext.Function.defer(resize_window, 1000);
+
+	    var tbh = me.tbar ? me.tbar.getHeight() : 0;
+	    var ps = applet.getPreferredSize();
+	    var aw = ps.width;
+	    var ah = ps.height;
+
+	    if (aw < 640) aw = 640;
+	    if (ah < 400) ah = 400;
+
+	    var oh;
+	    var ow;
+
+	    //console.log("size0 " + aw + " " + ah + " tbh " + tbh);
+
+	    if (window.innerHeight) {
+		oh = window.innerHeight;
+		ow = window.innerWidth;
+	    } else if (document.documentElement && 
+		       document.documentElement.clientHeight) {
+		oh = document.documentElement.clientHeight;
+		ow = document.documentElement.clientWidth;
+	    } else if (document.body) {
+		oh = document.body.clientHeight;
+		ow = document.body.clientWidth;
+	    }  else {
+		throw "can't get window size";
+	    }
+
+	    Ext.fly(applet).setSize(aw, ah + tbh);
+
+	    var offsetw = aw - ow;
+	    var offseth = ah + tbh - oh;
+
+	    if (offsetw !== 0 || offseth !== 0) {
+		//console.log("try resize by " + offsetw + " " + offseth);
+		try { window.resizeBy(offsetw, offseth); } catch (e) {}
+	    }
+
+	    Ext.Function.defer(resize_window, 1000);
+	};
+
+	var resize_box = function() {
+	    var applet = Ext.getDom(myid);
+
+	    if ((applet && Ext.isFunction(applet.getPreferredSize))) {
+		var ps = applet.getPreferredSize();
+		Ext.fly(applet).setSize(ps.width, ps.height);
+	    }
+
+	    Ext.Function.defer(resize_box, 1000);
+	};
+
+	var start_vnc_viewer = function(param) {
+	    var cert = param.cert;
+	    cert = cert.replace(/\n/g, "|");
+
+	    box.update({
+		id: myid,
+		border: false,
+		tag: 'applet',
+		code: 'com.tigervnc.vncviewer.VncViewer',
+		archive: '/vncterm/VncViewer.jar',
+		// NOTE: set size to '100%' -  else resize does not work
+		width: "100%",
+		height: "100%", 
+		cn: [
+		    {tag: 'param', name: 'id', value: myid},
+		    {tag: 'param', name: 'PORT', value: param.port},
+		    {tag: 'param', name: 'PASSWORD', value: param.ticket},
+		    {tag: 'param', name: 'USERNAME', value: param.user},
+		    {tag: 'param', name: 'Show Controls', value: 'No'},
+		    {tag: 'param', name: 'Offer Relogin', value: 'No'},
+		    {tag: 'param', name: 'PVECert', value: cert}
+		]
+	    });
+            if (me.toplevel) {
+		Ext.Function.defer(resize_window, 1000);
+            } else {
+		Ext.Function.defer(resize_box, 1000);
+            }
+	};
+
+	Ext.apply(me, {
+	    layout: 'fit',
+	    border: false,
+	    autoScroll: me.toplevel ? false : true,
+	    items: box,
+	    reloadApplet: function() {
+		Ext.Ajax.request({
+		    url: me.url,
+		    params: me.params,
+		    method: me.method || 'POST',
+		    failure: function(response, opts) {
+			box.update("Error " + response.status + ": " + response.statusText);
+		    },
+		    success: function(response, opts) {
+			var obj = Ext.decode(response.responseText);
+			start_vnc_viewer(obj.data);
+		    }
+		});
+	    }
+	});
+
+	me.callParent();
+
+	if (me.toplevel) {
+	    me.on("render", function() { me.reloadApplet();});
+	} else {
+	    me.on("show", function() { me.reloadApplet();});
+	    me.on("hide", function() { box.update(""); });
+	}
+    }
+});
+
+Ext.define('PVE.KVMConsole', {
+    extend: 'PVE.VNCConsole',
+    alias: ['widget.pveKVMConsole'],
+
+    initComponent : function() {
+	var me = this;
+ 
+	if (!me.nodename) 
+	    throw "no node name specified";
+
+	if (!me.vmid) 
+	    throw "no VM ID specified";
+
+	var vm_command = function(cmd, reload_applet) {
+	    me.setLoading(true, true);
+	    PVE.Utils.API2Request({
+		params: { command: cmd },
+		url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/status",
+		method: 'PUT',
+		callback: function() {
+		    me.setLoading(false);
+		},
+		failure: function(response, opts) {
+		    Ext.Msg.alert('Error', response.htmlStatus);
+		},
+		success: function() {
+		    if (reload_applet) 
+			Ext.Function.defer(me.reloadApplet, 1000, me);
+		}
+	    });
+	};
+
+	var tbar = [ 
+	    { 
+		text: 'Start',
+		handler: function() { 
+		    vm_command("start", 1);
+		}
+	    },
+	    { 
+		text: 'Stop',
+		handler: function() {
+		    var msg = "Do you really want to stop the VM?";
+		    Ext.Msg.confirm('Confirm', msg, function(btn) {
+			if (btn !== 'yes')
+			    return;
+			vm_command("stop");
+		    }); 
+		}
+	    },
+	    { 
+		text: 'Reset',
+		handler: function() { 
+		    var msg = "Do you really want to reset the VM?";
+		    Ext.Msg.confirm('Confirm', msg, function(btn) {
+			if (btn !== 'yes')
+			    return;
+			vm_command("reset");
+		    });
+		}
+	    },
+	    { 
+		text: 'Shutdown',
+		handler: function() {
+		    // normally, the OS ask the user, so we do not 
+		    // need a confirm here
+		    vm_command("shutdown"); 
+		}
+	    },
+	    { 
+		text: 'Suspend',
+		handler: function() {
+		    var msg = "Do you really want to suspend the VM?";
+		    Ext.Msg.confirm('Confirm', msg, function(btn) {
+			if (btn !== 'yes')
+			    return;
+			vm_command("suspend");
+		    }); 
+		}
+	    },
+	    { 
+		text: 'Resume',
+		handler: function() {
+		    vm_command("resume"); 
+		}
+	    },
+            '->',
+	    {
+                text: 'Refresh',
+		handler: function() { 
+		    var applet = Ext.getDom(me.appletID);
+		    applet.sendRefreshRequest();
+ 		}
+	    },
+ 	    {
+                text: 'Reload',
+                handler: function () { 
+		    me.reloadApplet(); 
+		}
+	    },
+            { 
+                text: 'Console',
+                handler: function() {
+		    var url = Ext.urlEncode({
+			console: 'kvm',
+			vmid: me.vmid,
+			node: me.nodename
+		    });
+                    var nw = window.open("?" + url, '_blank', 
+					 "innerWidth=745,innerheight=427");
+                    nw.focus();
+		}
+            }
+	];
+
+	Ext.apply(me, {
+	    tbar: tbar,
+	    url: "/api2/json/nodes/" + me.nodename + "/qemu/" + me.vmid + "/vncproxy"
+	});
+
+	me.callParent();
+    }
+});
\ No newline at end of file

Modified: pve-manager/pve2/www/new/index.pl
===================================================================
--- pve-manager/pve2/www/new/index.pl	2011-05-11 09:36:18 UTC (rev 5961)
+++ pve-manager/pve2/www/new/index.pl	2011-05-11 11:00:48 UTC (rev 5962)
@@ -5,6 +5,7 @@
 use Encode;
 use CGI;
 use PVE::pvecfg;
+use PVE::JSONSchema;
 use PVE::AccessControl;
 use PVE::REST;
 
@@ -40,14 +41,16 @@
 my %args =  $cgi->Vars();
 
 my $console = $args{console};
+my $vmid = $args{vmid} ? PVE::JSONSchema::pve_verify_vmid($args{vmid}) : 0;
+my $node = $args{node} ? PVE::JSONSchema::pve_verify_node_name($args{node}) : '';
 
 my $title = "Proxmox Virtual Environment";
 if (defined($console)) {
-    if ($console eq 'kvm' && $args{vmid}) {
-	my $name = "VM $args{vmid}"; # fixme: use real VM name
+    if ($console eq 'kvm') {
+	my $name = "VM $vmid"; # fixme: use real VM name
 	$title = "$name - Proxmox Console";
-    } elsif ($console eq 'shell' && $args{node}) {
-	$title = "node $args{node} - Proxmox Console";
+    } elsif ($console eq 'shell') {
+	$title = "node $node - Proxmox Shell";
     }
 }
 
@@ -57,24 +60,52 @@
 PVE.UserName = '$username';
 PVE.CSRFPreventionToken = '$token';
 
+// we need this (the java applet ignores the zindex)
+Ext.useShims = true;
+
 Ext.require([
     '*', 
     'Ext.state.*', 
     'Ext.tip.*', 
     'PVE.StateProvider', 
+    'PVE.VNCConsole', 
     'PVE.Workspace']);
 
-Ext.History.fieldid = 'x-history-field';
+_EOJS
 
-Ext.onReady(function() {
-    Ext.History.init();
-    Ext.tip.QuickTipManager.init();
-    Ext.state.Manager.setProvider(Ext.create('PVE.StateProvider'));
-    Ext.create('PVE.Workspace');
-});
+if (defined($console)) {
+
+    $jssrc .= <<_EOJS;
+    Ext.onReady(function() {
+	Ext.tip.QuickTipManager.init();
+	Ext.create('Ext.container.Viewport', {
+	  layout: 'fit',
+	  renderTo: Ext.getBody(),
+	  items: {
+	    xtype: 'pveKVMConsole',
+	    vmid: '$vmid',
+	    nodename: '$node',
+	    toplevel: true
+	  }
+        });
+    });
 _EOJS
 
+} else {
 
+    $jssrc .= <<_EOJS;
+
+    Ext.History.fieldid = 'x-history-field';
+
+    Ext.onReady(function() {
+	Ext.History.init();
+	Ext.tip.QuickTipManager.init();
+	Ext.state.Manager.setProvider(Ext.create('PVE.StateProvider'));
+	Ext.create('PVE.Workspace');
+    });
+_EOJS
+}
+
 my $page = <<_EOD;
 <html>
   <head>

Modified: pve-manager/pve2/www/new/qemu/Config.js
===================================================================
--- pve-manager/pve2/www/new/qemu/Config.js	2011-05-11 09:36:18 UTC (rev 5961)
+++ pve-manager/pve2/www/new/qemu/Config.js	2011-05-11 11:00:48 UTC (rev 5962)
@@ -49,15 +49,25 @@
 			{ 
 			    text: 'Stop',
 			    handler: function() {
-				vm_command('stop');
-			    }			    
-			}, 
+				var msg = "Do you really want to stop the VM?";
+				Ext.Msg.confirm('Confirm', msg, function(btn) {
+				    if (btn !== 'yes')
+					return;
+				    vm_command("stop");
+				}); 
+			    }
+			},
 			{ 
 			    text: 'Reset',
-			    handler: function() {
-				vm_command('reset');
-			    }			    
-			}, 
+			    handler: function() { 
+				var msg = "Do you really want to reset the VM?";
+				Ext.Msg.confirm('Confirm', msg, function(btn) {
+				    if (btn !== 'yes')
+					return;
+				    vm_command("reset");
+				});
+			    }
+			},
 			{ 
 			    text: 'Shutdown',
 			    handler: function() {
@@ -86,6 +96,19 @@
 				    });
 				}); 
 			    }
+			}, '->',
+			{ 
+			    text: 'Console',
+			    handler: function() {
+				var url = Ext.urlEncode({
+				    console: 'kvm',
+				    vmid: vmid,
+				    node: nodename
+				});
+				var nw = window.open("?" + url, '_blank', 
+						     "innerWidth=745,innerheight=427");
+				nw.focus();
+			    }
 			}
 		    ],
 		    html: 'summary ' + vmid
@@ -101,10 +124,11 @@
 		    html: 'options ' + vmid
 		},
 		{
-		    //xtype: 'pveConsole',
+		    xtype: 'pveKVMConsole',
 		    title: 'Console',
 		    itemId: 'console',
-		    html: 'console ' + vmid
+		    nodename: nodename,
+		    vmid: vmid
 		},
 		{
 		    title: 'Permissions',




More information about the pve-devel mailing list