Extract the logic for guest OS-type dependent machine version pinning into a dedicated helper, so it can be re-used.
Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> --- PVE/API2/Qemu.pm | 14 +++----------- PVE/QemuServer/Machine.pm | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 60b8a4cc..b1410df6 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1242,17 +1242,9 @@ __PACKAGE__->register_method({ $conf->{vmgenid} = PVE::QemuServer::generate_uuid(); } - my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine}); - my $machine = $machine_conf->{type}; - if (!$machine || $machine =~ m/^(?:pc|q35|virt)$/) { - # always pin Windows' machine version on create, they get to easily confused - if (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) { - $machine_conf->{type} = - PVE::QemuServer::Machine::windows_get_pinned_machine_version($machine); - $conf->{machine} = PVE::QemuServer::Machine::print_machine($machine_conf); - } - } - PVE::QemuServer::Machine::assert_valid_machine_property($machine_conf); + # always pin Windows' machine version on create, they get confused too easily + $conf->{machine} = PVE::QemuServer::Machine::check_and_pin_machine_string( + $conf->{machine}, $conf->{ostype}); $conf->{lock} = 'import' if $live_import_mapping; diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm index 40100555..e6fbd865 100644 --- a/PVE/QemuServer/Machine.pm +++ b/PVE/QemuServer/Machine.pm @@ -261,4 +261,20 @@ sub get_vm_machine { return $machine; } +sub check_and_pin_machine_string { + my ($machine_string, $ostype) = @_; + + my $machine_conf = parse_machine($machine_string); + my $machine = $machine_conf->{type}; + if (!$machine || $machine =~ m/^(?:pc|q35|virt)$/) { + # always pin Windows' machine version on create, they get confused too easily + if (PVE::QemuServer::Helpers::windows_version($ostype)) { + $machine_conf->{type} = windows_get_pinned_machine_version($machine); + } + } + + assert_valid_machine_property($machine_conf); + return print_machine($machine_conf); +} + 1; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel