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 <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2025-01-17 15:24:26 +01:00 committed by Thomas Lamprecht
parent 919e69d0d3
commit 7a9570f33e

View File

@ -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...)