From 7a9570f33e0b36dc61f7cae949f6c628f7a9b402 Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Fri, 17 Jan 2025 15:24:26 +0100 Subject: [PATCH] api: update vm config: pin machine version when switching to windows os type During virtual machine creation, the machine version is pinned when the guest OS is Windows. The same should be done when the guest OS type is newly set to Windows for consistency. NOTE RFC Signed-off-by: Fiona Ebner --- PVE/API2/Qemu.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index b1410df6..8acd8d9f 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -2109,6 +2109,24 @@ my $update_vm_api = sub { my $machine_conf = PVE::QemuServer::Machine::parse_machine($param->{$opt}); PVE::QemuServer::Machine::assert_valid_machine_property($machine_conf); $conf->{pending}->{$opt} = $param->{$opt}; + } elsif ($opt eq 'ostype') { + # Check if machine version pinning is needed when switching OS type, just like + # upon creation. Skip if 'machine' is explicitly set or removed at the same time + # to honor the users request. While it should be enough to look at $modified, + # because 'machine' is sorted before 'ostype', be explicit just to be sure. + if ( + !defined($param->{machine}) + && !defined($conf->{pending}->{machine}) + && !$modified->{machine} # detects deletion + ) { + eval { + $conf->{pending}->{machine} = + PVE::QemuServer::Machine::check_and_pin_machine_string( + $conf->{machine}, $param->{ostype}); + }; + print "automatic pinning of machine version failed - $@" if $@; + } + $conf->{pending}->{$opt} = $param->{$opt}; } elsif ($opt eq 'cipassword') { if (!PVE::QemuServer::Helpers::windows_version($conf->{ostype})) { # Same logic as in cloud-init (but with the regex fixed...)