mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-07-20 06:15:13 +00:00

Avoid pushing our array of downstream revisions to the array of upstream machines if we create completely new array on return anyway, just let sort iterate over both arrays instead. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
90 lines
2.1 KiB
Perl
90 lines
2.1 KiB
Perl
package PVE::API2::Qemu::Machine;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use JSON;
|
|
|
|
use PVE::JSONSchema qw(get_standard_option);
|
|
use PVE::QemuServer::Machine;
|
|
use PVE::RESTHandler;
|
|
use PVE::Tools qw(file_get_contents);
|
|
|
|
use base qw(PVE::RESTHandler);
|
|
|
|
__PACKAGE__->register_method({
|
|
name => 'types',
|
|
path => '',
|
|
method => 'GET',
|
|
proxyto => 'node',
|
|
description => "Get available QEMU/KVM machine types.",
|
|
permissions => {
|
|
user => 'all',
|
|
},
|
|
parameters => {
|
|
additionalProperties => 0,
|
|
properties => {
|
|
node => get_standard_option('pve-node'),
|
|
},
|
|
},
|
|
returns => {
|
|
type => 'array',
|
|
items => {
|
|
type => 'object',
|
|
additionalProperties => 1,
|
|
properties => {
|
|
id => {
|
|
type => 'string',
|
|
description => "Full name of machine type and version.",
|
|
},
|
|
type => {
|
|
type => 'string',
|
|
enum => ['q35', 'i440fx'],
|
|
description => "The machine type.",
|
|
},
|
|
version => {
|
|
type => 'string',
|
|
description => "The machine version.",
|
|
},
|
|
changes => {
|
|
type => 'string',
|
|
optional => 1,
|
|
description => 'Notable changes of a version, currently only set for +pveX versions.',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
code => sub {
|
|
my $supported_machine_list = eval {
|
|
my $raw = file_get_contents('/usr/share/kvm/machine-versions-x86_64.json');
|
|
my $machines = from_json($raw, { utf8 => 1 });
|
|
|
|
my $to_add = [];
|
|
|
|
for my $machine ($machines->@*) {
|
|
my $base_version = $machine->{version};
|
|
my $pvever = PVE::QemuServer::Machine::get_pve_version($base_version);
|
|
for (my $i = 1; $i <= $pvever; $i++) {
|
|
my $version = $base_version . "+pve$i";
|
|
my $entry = {
|
|
id => $machine->{id} . "+pve$i",
|
|
type => $machine->{type},
|
|
version => $version,
|
|
};
|
|
|
|
my $desc = PVE::QemuServer::Machine::get_pve_version_description($version);
|
|
$entry->{changes} = $desc if defined($desc);
|
|
|
|
push $to_add->@*, $entry;
|
|
}
|
|
}
|
|
|
|
return [ sort { $b->{id} cmp $a->{id} } ($machines->@*, $to_add->@*) ]; # merge & sort
|
|
};
|
|
die "could not load supported machine versions - $@\n" if $@;
|
|
return $supported_machine_list;
|
|
}
|
|
});
|
|
|
|
1;
|