Signed-off-by: Fabian Ebner <f.eb...@proxmox.com>
---
 PVE/API2/Qemu.pm | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index c56b609..f20cd76 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -836,6 +836,7 @@ __PACKAGE__->register_method({
            { subdir => 'spiceproxy' },
            { subdir => 'sendkey' },
            { subdir => 'firewall' },
+           { subdir => 'upgradeqemu' },
            ];
 
        return $res;
@@ -4395,4 +4396,63 @@ __PACKAGE__->register_method({
        return PVE::QemuServer::Cloudinit::dump_cloudinit_config($conf, 
$param->{vmid}, $param->{type});
     }});
 
+__PACKAGE__->register_method({
+    name => 'upgrade_qemu',
+    path => '{vmid}/upgradeqemu',
+    method => 'POST',
+    protected => 1,
+    proxyto => 'node',
+    description => "Upgrade the running QEMU version of the VM to the 
currently installed one.",
+    permissions => {
+       check => ['perm', '/vms/{vmid}', [ 'VM.PowerMgmt' ]],
+    },
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           vmid => get_standard_option('pve-vmid',
+               { completion => \&PVE::QemuServer::complete_vmid }),
+       },
+    },
+    returns => {
+       type => 'string',
+       description => "the task ID.",
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $rpcenv = PVE::RPCEnvironment::get();
+       my $authuser = $rpcenv->get_user();
+
+       my $node = extract_param($param, 'node');
+       my $vmid = extract_param($param, 'vmid');
+
+       my $check_and_load_config = sub {
+           PVE::QemuConfig::assert_config_exists_on_node($vmid, $node);
+           PVE::QemuServer::Helpers::vm_running_locally($vmid) or die "VM is 
not running\n";
+
+           # TODO check if running version is actually outdated
+
+           my $conf = PVE::QemuConfig->load_config($vmid);
+           PVE::QemuConfig->check_lock($conf);
+
+           return $conf;
+       };
+
+       $check_and_load_config->();
+
+       # TODO ensure HA is happy with what we do
+
+       my $realcmd = sub {
+           my $conf = $check_and_load_config->();
+           PVE::QemuServer::upgrade_qemu($vmid, $conf);
+       };
+
+       my $worker = sub {
+           return PVE::QemuConfig->lock_config($vmid, $realcmd);
+       };
+
+       return $rpcenv->fork_worker('qemuupgrade', $vmid, $authuser, $worker);
+    }});
+
 1;
-- 
2.20.1



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to