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

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Sep 10 17:50:47 CEST 2010


Author: dietmar
Date: 2010-09-10 15:50:47 +0000 (Fri, 10 Sep 2010)
New Revision: 5119

Modified:
   qemu-server/pve2/ChangeLog
   qemu-server/pve2/PVE/API2/QemuServer.pm
   qemu-server/pve2/QemuServer.pm
   qemu-server/pve2/nqm
   qemu-server/pve2/qm
Log:
	* nqm: implement wait, showcmd and  startall



Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog	2010-09-10 15:48:20 UTC (rev 5118)
+++ qemu-server/pve2/ChangeLog	2010-09-10 15:50:47 UTC (rev 5119)
@@ -1,5 +1,7 @@
 2010-09-10  Proxmox Support Team  <support at proxmox.com>
 
+	* nqm: implement wait, showcmd and  startall
+
 	* QemuServer.pm: register all options with
 	PVE::JSONSchema::register_standard_option()
 

Modified: qemu-server/pve2/PVE/API2/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/API2/QemuServer.pm	2010-09-10 15:48:20 UTC (rev 5118)
+++ qemu-server/pve2/PVE/API2/QemuServer.pm	2010-09-10 15:50:47 UTC (rev 5119)
@@ -10,6 +10,7 @@
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RESTHandler;
 use PVE::QemuServer;
+use PVE::RPCEnvironment;
 
 use Data::Dumper; # fixme: remove
 
@@ -69,7 +70,7 @@
 
 __PACKAGE__->register_method ({
     name => 'vmlist', 
-    path => '{node}', 
+    path => 'config/{node}', 
     method => 'GET',
     description => "Virtual machine index.",
     parameters => {
@@ -97,7 +98,7 @@
 
 __PACKAGE__->register_method ({
     name => 'create_vm', 
-    path => '{node}', 
+    path => 'config/{node}', 
     method => 'POST',
     description => "Create new virtual machine.",
     parameters => {
@@ -177,7 +178,7 @@
 
 __PACKAGE__->register_method ({
     name => 'update_vm', 
-    path => '{node}/{vmid}', 
+    path => 'config/{node}/{vmid}', 
     method => 'PUT',
     description => "Set virtual machine options.",
     parameters => {
@@ -202,14 +203,20 @@
     code => sub {
 	my ($param) = @_;
 
+	my $rpcenv = PVE::RPCEnvironment::get();
 
+	my $user = $rpcenv->get_user();
+
 	my $node = extract_param($param, 'node');
 
 	# fixme: proxy to correct node
 	# fixme: fork worker?
 
 	my $vmid = extract_param($param, 'vmid');
+
 	my $skiplock = extract_param($param, 'skiplock');
+	raise_param_exc({ skiplock => "Only root may use this option." }) if $user ne 'root';
+
 	my $delete = extract_param($param, 'delete');
 
 	die "no options specified\n" if !$delete && !scalar(keys %$param);
@@ -255,7 +262,7 @@
 
 __PACKAGE__->register_method ({
     name => 'vm_config', 
-    path => '{node}/{vmid}', 
+    path => 'config/{node}/{vmid}', 
     method => 'GET',
     description => "Get virtual machine configuration.",
     parameters => {

Modified: qemu-server/pve2/QemuServer.pm
===================================================================
--- qemu-server/pve2/QemuServer.pm	2010-09-10 15:48:20 UTC (rev 5118)
+++ qemu-server/pve2/QemuServer.pm	2010-09-10 15:50:47 UTC (rev 5119)
@@ -1322,7 +1322,11 @@
 
     my $filename = config_file ($vmid);
 
-    return read_file($filename);
+    my $conf = read_file($filename);
+
+    die "no such VM ('$vmid')\n" if !defined($conf);
+
+    return $conf;
 }  
 
 sub parse_config {
@@ -1670,7 +1674,6 @@
 	$d->{disk} = 0;
 	$d->{cpus} = ($conf->{sockets} || 1) * ($conf->{cores} || 1);
 	$d->{name} = $conf->{name} || "VM$veid";
-
 	$d->{maxmem} = $conf->{memory} ? $conf->{memory} : 0; 
 
 	$d->{maxdisk} = $conf->{disksize} ? int($conf->{disksize}*1024) : 0;
@@ -2277,7 +2280,8 @@
     });
 }
 
-sub vm_wait {
+# fixme: remove
+sub vm_wait_old {
     my ($self, $vmid, $timeout, $nolog) = @_;
 
     my $pid = check_running ($vmid);
@@ -2498,7 +2502,8 @@
     });
 }
 
-sub vm_startall {
+# fixme: remove
+sub vm_startall_old {
     my ($self) = @_;
 
     my $vzlist = vzlist();
@@ -2507,7 +2512,7 @@
 	next if $vzlist->{$vmid}->{pid}; # already running
 
 	eval {
-	    my $conf =  load_config ($vmid);
+	    my $conf = load_config ($vmid);
 	    if ($conf->{onboot}) {
 		print STDERR "Starting Qemu VM $vmid\n";
 		$self->vm_start ($vmid);

Modified: qemu-server/pve2/nqm
===================================================================
--- qemu-server/pve2/nqm	2010-09-10 15:48:20 UTC (rev 5118)
+++ qemu-server/pve2/nqm	2010-09-10 15:50:47 UTC (rev 5119)
@@ -9,6 +9,7 @@
 use PVE::RPCEnvironment;
 use PVE::QemuServer;
 use PVE::API2::QemuServer;
+use PVE::JSONSchema qw(get_standard_option);
 
 use PVE::CLIHandler;
 
@@ -28,6 +29,99 @@
 
 my $hostname = read_file('hostname');
 
+__PACKAGE__->register_method ({
+    name => 'showcmd', 
+    path => 'showcmd', 
+    method => 'GET',
+    description => "Show command line which is used to start the VM (debug info).",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid'),
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $qm = PVE::QemuServer->new();
+	print $qm->vm_commandline ($param->{vmid}) . "\n";
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'startall', 
+    path => 'startall', 
+    method => 'POST',
+    description => "Start all virtual machines (when onboot=1).",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $vzlist = PVE::QemuServer::vzlist();
+
+	foreach my $vmid (keys %$vzlist) {
+	    next if $vzlist->{$vmid}->{pid}; # already running
+
+	    eval {
+		my $conf = PVE::QemuServer::load_config ($vmid);
+		if ($conf->{onboot}) {
+		    print STDERR "Starting Qemu VM $vmid\n";
+		    my $qm = PVE::QemuServer->new();
+		    $qm->vm_start ($vmid);
+		}
+	    };
+	    print STDERR $@ if $@;
+	}
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'wait', 
+    path => 'wait', 
+    method => 'GET',
+    description => "Wait until the VM is stopped.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid'),
+	    timeout => {
+		description => "Timeout in seconds. Default is to wait forever.",
+		type => 'integer',
+		minimum => 1,
+		optional => 1,
+	    }
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $vmid = $param->{vmid};
+	my $timeout = $param->{timeout};
+
+	my $pid = PVE::QemuServer::check_running ($vmid);
+	return if !$pid;
+
+	print "waiting until VM $vmid stopps (PID $pid)\n";
+
+	my $count = 0;
+	while ((!$timeout || ($count < $timeout)) && PVE::QemuServer::check_running ($vmid)) {
+	    $count++;
+	    sleep 1;
+	}
+
+	die "wait failed - got timeout\n" if PVE::QemuServer::check_running ($vmid);
+
+	return undef;
+    }});
+
 my $cmddef = {
     list => [ "PVE::API2::QemuServer", 'vmlist', [],
 	     { node => $hostname }, sub {
@@ -58,7 +152,13 @@
 			print "$k: $v\n";
 		    }
 		}],
-		
+	
+    showcmd => [ __PACKAGE__, 'showcmd', ['vmid']],
+
+    wait => [ __PACKAGE__, 'wait', ['vmid']],
+
+    startall => [ __PACKAGE__, 'startall', []],
+	
 };
 
 my $cmd = shift;

Modified: qemu-server/pve2/qm
===================================================================
--- qemu-server/pve2/qm	2010-09-10 15:48:20 UTC (rev 5118)
+++ qemu-server/pve2/qm	2010-09-10 15:50:47 UTC (rev 5119)
@@ -485,7 +485,7 @@
 	exit (-1);
     }    
 
-    $qm->vm_startall ();
+    $qm->vm_startall_old ();
 
 } elsif ($cmd eq 'reset') {
     if (scalar (@ARGV) != 0) {
@@ -516,7 +516,7 @@
 	exit (-1);
     }
 
-    $qm->vm_wait ($vmid, $timeout);
+    $qm->vm_wait_old ($vmid, $timeout);
 
 } elsif ($cmd eq 'stopall') {
     my $timeout = shift || 0;




More information about the pve-devel mailing list