It's necessary to numerically compare versions in machine types, so introduce a new helper which does that.
Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> --- src/PVE/API2/Qemu/Machine.pm | 6 +++++- src/PVE/QemuServer/Machine.pm | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/PVE/API2/Qemu/Machine.pm b/src/PVE/API2/Qemu/Machine.pm index 41281af2..0fc1ea6c 100644 --- a/src/PVE/API2/Qemu/Machine.pm +++ b/src/PVE/API2/Qemu/Machine.pm @@ -81,7 +81,11 @@ __PACKAGE__->register_method({ } } - return [sort { $b->{id} cmp $a->{id} } ($machines->@*, $pve_machines->@*)]; # merge & sort + return [ + sort { + PVE::QemuServer::Machine::machine_version_cmp($b->{id}, $a->{id}) + } ($machines->@*, $pve_machines->@*) + ]; # merge & sort }; die "could not load supported machine versions - $@\n" if $@; return $supported_machine_list; diff --git a/src/PVE/QemuServer/Machine.pm b/src/PVE/QemuServer/Machine.pm index 3d98ee0b..9d17344a 100644 --- a/src/PVE/QemuServer/Machine.pm +++ b/src/PVE/QemuServer/Machine.pm @@ -198,6 +198,30 @@ sub extract_version { return; } +=head3 machine_version_cmp + + sort { machine_version_cmp($a, $b) } @machine_types + +Comparision function for sorting machine types by version. + +=cut + +sub machine_version_cmp { + my ($machine_type_a, $machine_type_b) = @_; + + my ($major_a, $minor_a, $pve_a) = extract_version_parts($machine_type_a); + my ($major_b, $minor_b, $pve_b) = extract_version_parts($machine_type_b); + + return PVE::QemuServer::Helpers::version_cmp( + $major_a, + $major_b, + $minor_a, + $minor_b, + $pve_a, + $pve_b, + ); +} + sub is_machine_version_at_least { my ($machine_type, $major, $minor, $pve) = @_; -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel