[pve-devel] [PATCH qemu-server 3/3] api create: allow auto vm start after create finished
Thomas Lamprecht
t.lamprecht at proxmox.com
Fri Jun 1 16:37:41 CEST 2018
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
This could also be done differently, by not calling into the API method
(which forks again a new worker) but calling directly
PVE::QemuServer->vm_start(...) - with that we won't get a extra task log
though...
(oh and naturally this would be added to CTs too)
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.17.1
More information about the pve-devel
mailing list