]> git.proxmox.com Git - qemu-server.git/commitdiff
add timeout parameter for stop/shotdown
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 11 Oct 2011 09:58:34 +0000 (11:58 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 11 Oct 2011 09:58:34 +0000 (11:58 +0200)
PVE/API2/Qemu.pm

index eba65b516f13883c57c1d0fcfe57a51b3531d6ba..b8bd5dac239487fe353ab423620e551c4c4fd40f 100644 (file)
@@ -804,6 +804,12 @@ __PACKAGE__->register_method({
            node => get_standard_option('pve-node'),
            vmid => get_standard_option('pve-vmid'),
            skiplock => get_standard_option('skiplock'),
+           timeout => {
+               description => "Wait maximal timeout seconds.",
+               type => 'integer',
+               minimum => 0,
+               optional => 1,
+           }
        },
     },
     returns => { 
@@ -831,6 +837,21 @@ __PACKAGE__->register_method({
 
            PVE::QemuServer::vm_stop($vmid, $skiplock);
 
+           my $pid = PVE::QemuServer::check_running ($vmid);
+
+           if ($pid && $param->{timeout}) {
+               print "waiting until VM $vmid stopps (PID $pid)\n";
+
+               my $count = 0;
+               while (($count < $param->{timeout}) && 
+                      PVE::QemuServer::check_running($vmid)) {
+                   $count++;
+                   sleep 1;
+               }
+
+               die "wait failed - got timeout\n" if PVE::QemuServer::check_running($vmid);
+           }
+
            return;
        };
 
@@ -896,6 +917,12 @@ __PACKAGE__->register_method({
            node => get_standard_option('pve-node'),
            vmid => get_standard_option('pve-vmid'),
            skiplock => get_standard_option('skiplock'),
+           timeout => {
+               description => "Wait maximal timeout seconds.",
+               type => 'integer',
+               minimum => 0,
+               optional => 1,
+           }
        },
     },
     returns => { 
@@ -923,6 +950,21 @@ __PACKAGE__->register_method({
 
            PVE::QemuServer::vm_shutdown($vmid, $skiplock);
 
+           my $pid = PVE::QemuServer::check_running ($vmid);
+
+           if ($pid && $param->{timeout}) {
+               print "waiting until VM $vmid stopps (PID $pid)\n";
+
+               my $count = 0;
+               while (($count < $param->{timeout}) && 
+                      PVE::QemuServer::check_running($vmid)) {
+                   $count++;
+                   sleep 1;
+               }
+
+               die "wait failed - got timeout\n" if PVE::QemuServer::check_running($vmid);
+           }
+
            return;
        };