[pve-devel] r5128 - in qemu-server/pve2: . PVE/API2

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Sep 13 14:19:14 CEST 2010


Author: dietmar
Date: 2010-09-13 12:19:14 +0000 (Mon, 13 Sep 2010)
New Revision: 5128

Modified:
   qemu-server/pve2/ChangeLog
   qemu-server/pve2/PVE/API2/QemuServerStatus.pm
   qemu-server/pve2/nqm
Log:
	* nqm: implement vncticket
	(run_vnc_proxy): impl. vncproxy


Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog	2010-09-13 11:53:21 UTC (rev 5127)
+++ qemu-server/pve2/ChangeLog	2010-09-13 12:19:14 UTC (rev 5128)
@@ -1,6 +1,7 @@
 2010-09-13  Proxmox Support Team  <support at proxmox.com>
 
 	* nqm: implement vncticket
+	(run_vnc_proxy): impl. vncproxy
 
 	* PVE/API2/QemuServer.pm: implement destroy_vm()
 

Modified: qemu-server/pve2/PVE/API2/QemuServerStatus.pm
===================================================================
--- qemu-server/pve2/PVE/API2/QemuServerStatus.pm	2010-09-13 11:53:21 UTC (rev 5127)
+++ qemu-server/pve2/PVE/API2/QemuServerStatus.pm	2010-09-13 12:19:14 UTC (rev 5128)
@@ -70,8 +70,7 @@
 		    type => 'string',
 		    optional => 1,
 		    minLength => 8, # just to improve security
-		    pattern => '[A-Za-z0-9\+\/\=]+', # base64 characters
-		    
+		    pattern => '[A-Za-z0-9\+\/\=]+', # base64 characters		    
 		},
 	    }),
     },

Modified: qemu-server/pve2/nqm
===================================================================
--- qemu-server/pve2/nqm	2010-09-13 11:53:21 UTC (rev 5127)
+++ qemu-server/pve2/nqm	2010-09-13 12:19:14 UTC (rev 5128)
@@ -4,6 +4,8 @@
 use Getopt::Long;
 use Fcntl ':flock';
 use File::Path;
+use IO::Socket::UNIX;
+use IO::Select;
 
 use PVE::INotify qw(read_file);
 use PVE::RPCEnvironment;
@@ -31,6 +33,47 @@
 
 my $hostname = read_file('hostname');
 
+sub run_vnc_proxy {
+    my ($vmid) = @_;
+
+    my $path = PVE::QemuServer::vnc_socket ($vmid);
+
+    my $s = IO::Socket::UNIX->new (Peer => $path, Timeout => 120);
+
+    die "unable to connect to socket '$path' - $!" if !$s;
+
+    my $select = new IO::Select;
+
+    $select->add (\*STDIN);
+    $select->add ($s);
+
+    my $timeout = 60*15; # 15 minutes
+
+    my @handles;
+    while ($select->count && 
+	   scalar (@handles = $select->can_read ($timeout))) {
+	foreach my $h (@handles) {
+	    my $buf;
+	    my $n = $h->sysread ($buf, 4096);
+
+	    if ($h == \*STDIN) {
+		if ($n) {
+		    syswrite ($s, $buf);
+		} else {
+		    exit (0);
+		}
+	    } elsif ($h == $s) {
+		if ($n) {
+		    syswrite (\*STDOUT, $buf);
+		} else {
+		    exit (0);
+		}
+	    }
+	}
+    }
+    exit (0);
+}
+
 __PACKAGE__->register_method ({
     name => 'showcmd', 
     path => 'showcmd', 
@@ -106,6 +149,40 @@
     }});
 
 __PACKAGE__->register_method ({
+    name => 'vncproxy', 
+    path => 'vncproxy', 
+    method => 'PUT',
+    description => "Run a VNC proxy ",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid'),
+	    ticket => { 
+		description => "VNC auth ticket.",
+		type => 'string',
+		optional => 1,
+		minLength => 8, # just to improve security
+		pattern => '[A-Za-z0-9\+\/\=]+', # base64 characters
+	    },
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $vmid = $param->{vmid};
+	my $ticket = $param->{ticket};
+
+	if ($ticket) {
+	    PVE::QemuServer::vm_vncticket ($vmid, $ticket);
+	}
+
+	run_vnc_proxy ($vmid, $ticket);
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
     name => 'unlock', 
     path => 'unlock', 
     method => 'PUT',
@@ -130,6 +207,30 @@
     }});
 
 __PACKAGE__->register_method ({
+    name => 'mtunnel', 
+    path => 'mtunnel', 
+    method => 'POST',
+    description => "Used by vzmigrate - do not use manually.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	print "tunnel online\n";
+	*STDOUT->flush();
+
+	while (my $line = <>) {
+	    chomp $line;
+	    last if $line =~ m/^quit$/;
+	}
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
     name => 'startall', 
     path => 'startall', 
     method => 'POST',
@@ -270,9 +371,6 @@
 # fixme: unlink
 # fixme: cdrom
 
-# fixme: vncproxy, vnc
-# fixme: mtunnel
-
 my $cmddef = {
     list => [ "PVE::API2::QemuServer", 'vmlist', [],
 	     { node => $hostname }, sub {
@@ -312,6 +410,8 @@
 
     vncticket => [ __PACKAGE__, 'vncticket', ['vmid']],
 
+    vncproxy => [ __PACKAGE__, 'vncproxy', ['vmid', 'ticket']],
+
     wait => [ __PACKAGE__, 'wait', ['vmid']],
 
     unlock => [ __PACKAGE__, 'unlock', ['vmid']],
@@ -322,7 +422,9 @@
 
     stopall => [ __PACKAGE__, 'stopall', []],
 
+    mtunnel => [ __PACKAGE__, 'mtunnel', []],
 
+
     start => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 
 	       { node => $hostname, command => 'start' } ],
     stop => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 



More information about the pve-devel mailing list