]> git.proxmox.com Git - qemu-server.git/blob - PVE/API2/Qemu/CPU.pm
api: allow listing custom and default CPU models
[qemu-server.git] / PVE / API2 / Qemu / CPU.pm
1 package PVE::API2::Qemu::CPU;
2
3 use strict;
4 use warnings;
5
6 use PVE::RESTHandler;
7 use PVE::JSONSchema qw(get_standard_option);
8 use PVE::QemuServer::CPUConfig;
9
10 use base qw(PVE::RESTHandler);
11
12 __PACKAGE__->register_method({
13 name => 'index',
14 path => '',
15 method => 'GET',
16 description => 'List all custom and default CPU models.',
17 permissions => {
18 user => 'all',
19 description => 'Only returns custom models when the current user has'
20 . ' Sys.Audit on /nodes.',
21 },
22 parameters => {
23 additionalProperties => 0,
24 properties => {
25 node => get_standard_option('pve-node'),
26 },
27 },
28 returns => {
29 type => 'array',
30 items => {
31 type => 'object',
32 properties => {
33 name => {
34 type => 'string',
35 description => "Name of the CPU model. Identifies it for"
36 . " subsequent API calls. Prefixed with"
37 . " 'custom-' for custom models.",
38 },
39 custom => {
40 type => 'boolean',
41 description => "True if this is a custom CPU model.",
42 },
43 vendor => {
44 type => 'string',
45 description => "CPU vendor visible to the guest when this"
46 . " model is selected. Vendor of"
47 . " 'reported-model' in case of custom models.",
48 },
49 },
50 },
51 links => [ { rel => 'child', href => '{name}' } ],
52 },
53 code => sub {
54 my $rpcenv = PVE::RPCEnvironment::get();
55 my $authuser = $rpcenv->get_user();
56 my $include_custom = $rpcenv->check($authuser, "/nodes", ['Sys.Audit'], 1);
57
58 return PVE::QemuServer::CPUConfig::get_cpu_models($include_custom);
59 }});
60
61 1;