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.eb...@proxmox.com>
---
 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...)
-- 
2.39.5



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

Reply via email to