mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-03 01:29:13 +00:00
machine: add check_and_pin_machine_string() helper
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.ebner@proxmox.com>
This commit is contained in:
parent
455e12636f
commit
919e69d0d3
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user