]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
activate LVM LVs more carefully
[qemu-server.git] / PVE / API2 / Qemu.pm
index 98b306f989cde8743766b71b420fc47adb5283b0..376a9b2445b7c6d4bedaa328b0f360f35c0a49bf 100644 (file)
@@ -622,6 +622,10 @@ __PACKAGE__->register_method({
        my $storecfg = PVE::Storage::config(); 
 
        my $realcmd = sub {
+           my $upid = shift;
+
+           syslog('info', "destroy VM $vmid: $upid\n");
+
            PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
        };
 
@@ -807,7 +811,7 @@ __PACKAGE__->register_method({
        # test if VM exists
        my $conf = PVE::QemuServer::load_config($param->{vmid});
 
-       my $vmstatus =  PVE::QemuServer::vmstatus($param->{vmid});
+       my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
 
        return $vmstatus->{$param->{vmid}};
     }});
@@ -850,6 +854,8 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
+       die "VM $vmid already running\n" if PVE::QemuServer::check_running($vmid);
+
        my $storecfg = PVE::Storage::config(); 
 
        my $realcmd = sub {
@@ -904,27 +910,16 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
+       die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+
+       my $storecfg = PVE::Storage::config();
+
        my $realcmd = sub {
            my $upid = shift;
 
            syslog('info', "stop VM $vmid: $upid\n");
 
-           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);
-           }
+           PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, $param->{timeout});
 
            return;
        };
@@ -965,11 +960,11 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
+       die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+
        my $realcmd = sub {
            my $upid = shift;
 
-           syslog('info', "reset VM $vmid: $upid\n");
-
            PVE::QemuServer::vm_reset($vmid, $skiplock);
 
            return;
@@ -1017,27 +1012,14 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
+       die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+
        my $realcmd = sub {
            my $upid = shift;
 
            syslog('info', "shutdown VM $vmid: $upid\n");
 
-           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);
-           }
+           PVE::QemuServer::vm_shutdown($vmid, $skiplock, $param->{timeout});
 
            return;
        };
@@ -1078,6 +1060,8 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
+       die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+
        my $realcmd = sub {
            my $upid = shift;
 
@@ -1124,6 +1108,8 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
+       die "VM $vmid already running\n" if PVE::QemuServer::check_running($vmid);
+
        my $realcmd = sub {
            my $upid = shift;