]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
check also pending changes when reverting/deleting
[qemu-server.git] / PVE / API2 / Qemu.pm
index 3342458929cff5176d7ad734854bdd112a94d16f..54db5ab0caaf43255dcf8d73fb9262eddd31c32c 100644 (file)
@@ -15,6 +15,8 @@ use PVE::Exception qw(raise raise_param_exc raise_perm_exc);
 use PVE::Storage;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RESTHandler;
+use PVE::ReplicationConfig;
+use PVE::GuestHelpers;
 use PVE::QemuConfig;
 use PVE::QemuServer;
 use PVE::QemuMigrate;
@@ -1010,7 +1012,7 @@ my $update_vm_api  = sub {
            foreach my $opt (@delete) {
                $modified->{$opt} = 1;
                $conf = PVE::QemuConfig->load_config($vmid); # update/reload
-               if (!defined($conf->{$opt})) {
+               if (!defined($conf->{$opt}) && !defined($conf->{pending}->{$opt})) {
                    warn "cannot delete '$opt' - not set in current configuration!\n";
                    $modified->{$opt} = 0;
                    next;
@@ -1279,6 +1281,10 @@ __PACKAGE__->register_method({
        die "unable to remove VM $vmid - used in HA resources\n"
            if PVE::HA::Config::vm_is_ha_managed($vmid);
 
+       # do not allow destroy if there are replication jobs
+       my $repl_conf = PVE::ReplicationConfig->new();
+       $repl_conf->check_for_existing_jobs($vmid);
+
        # early tests (repeat after locking)
        die "VM $vmid is running - destroy failed\n"
            if PVE::QemuServer::check_running($vmid);
@@ -2851,13 +2857,17 @@ __PACKAGE__->register_method({
 
        } else {
 
-           my $realcmd = sub {
-               my $upid = shift;
+           my $code = sub {
+               my $realcmd = sub {
+                   my $upid = shift;
+
+                   PVE::QemuMigrate->migrate($target, $targetip, $vmid, $param);
+               };
 
-               PVE::QemuMigrate->migrate($target, $targetip, $vmid, $param);
+               return $rpcenv->fork_worker('qmigrate', $vmid, $authuser, $realcmd);
            };
 
-           return $rpcenv->fork_worker('qmigrate', $vmid, $authuser, $realcmd);
+           return PVE::GuestHelpers::guest_migration_lock($vmid, 10, $code);
        }
 
     }});