]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
vmconfig_apply_pending: add error handling
[qemu-server.git] / PVE / API2 / Qemu.pm
index cf9da166ea9a9e19d615c158aaec1f21416ad775..e853a8355f4456f662cb2b4cc619dffa47c77219 100644 (file)
@@ -574,17 +574,18 @@ __PACKAGE__->register_method({
                }
 
                PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
-
-               if ($start_after_create) {
-                   eval { PVE::API2::Qemu->vm_start({ vmid => $vmid, node => $node }) };
-                   warn $@ if $@;
-               }
            };
 
            # ensure no old replication state are exists
            PVE::ReplicationState::delete_guest_states($vmid);
 
-           return PVE::QemuConfig->lock_config_full($vmid, 1, $realcmd);
+           PVE::QemuConfig->lock_config_full($vmid, 1, $realcmd);
+
+           if ($start_after_create) {
+               print "Execute autostart\n";
+               eval { PVE::API2::Qemu->vm_start({ vmid => $vmid, node => $node }) };
+               warn $@ if $@;
+           }
        };
 
        my $createfn = sub {
@@ -1241,13 +1242,13 @@ my $update_vm_api  = sub {
 
            $conf = PVE::QemuConfig->load_config($vmid); # update/reload
 
+           my $errors = {};
            if ($running) {
-               my $errors = {};
                PVE::QemuServer::vmconfig_hotplug_pending($vmid, $conf, $storecfg, $modified, $errors);
-               raise_param_exc($errors) if scalar(keys %$errors);
            } else {
-               PVE::QemuServer::vmconfig_apply_pending($vmid, $conf, $storecfg, $running);
+               PVE::QemuServer::vmconfig_apply_pending($vmid, $conf, $storecfg, $running, $errors);
            }
+           raise_param_exc($errors) if scalar(keys %$errors);
 
            return;
        };