From e33f774d00a6a79518923bf96f38cef529e6a4f9 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 1 Jun 2018 16:37:41 +0200 Subject: [PATCH] api create: allow auto vm start after create finished Signed-off-by: Thomas Lamprecht --- PVE/API2/Qemu.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index f499525..a5ab282 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -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'; -- 2.39.2