]> git.proxmox.com Git - qemu-server.git/commitdiff
api create: allow auto vm start after create finished
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 1 Jun 2018 14:37:41 +0000 (16:37 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 12 Jun 2018 07:44:39 +0000 (09:44 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Qemu.pm

index f499525aa09f48c5570a9f69dde8b6322a56898b..a5ab282e91cd3d5dd6e241236581b407a6d7a532 100644 (file)
@@ -444,7 +444,13 @@ __PACKAGE__->register_method({
                    optional => 1,
                    type => 'integer',
                    minimum => '0',
-               }
+               },
+               start => {
+                   optional => 1,
+                   type => 'boolean',
+                   default => 0,
+                   description => "Start VM after it was created successfully.",
+               },
            }),
     },
     returns => {
@@ -474,6 +480,8 @@ __PACKAGE__->register_method({
 
        my $bwlimit = extract_param($param, 'bwlimit');
 
+       my $start_after_create = extract_param($param, 'start');
+
        my $filename = PVE::QemuConfig->config_file($vmid);
 
        my $storecfg = PVE::Storage::config();
@@ -555,6 +563,8 @@ __PACKAGE__->register_method({
                    bwlimit => $bwlimit, });
 
                PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
+
+               PVE::API2::Qemu->vm_start({ vmid => $vmid, node => $node }) if $start_after_create;
            };
 
            # ensure no old replication state are exists
@@ -603,7 +613,12 @@ __PACKAGE__->register_method({
                PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
            };
 
-           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";
+               PVE::API2::Qemu->vm_start({vmid => $vmid, node => $node});
+           }
        };
 
        my $worker_name = $is_restore ? 'qmrestore' : 'qmcreate';