From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 04C4B79F49 for ; Thu, 28 Oct 2021 13:42:00 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EAE241F966 for ; Thu, 28 Oct 2021 13:41:59 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 5E7A81F90E for ; Thu, 28 Oct 2021 13:41:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 38FCF469AE for ; Thu, 28 Oct 2021 13:41:57 +0200 (CEST) From: Stefan Reiter To: pve-devel@lists.proxmox.com Date: Thu, 28 Oct 2021 13:41:44 +0200 Message-Id: <20211028114150.3245864-4-s.reiter@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211028114150.3245864-1-s.reiter@proxmox.com> References: <20211028114150.3245864-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.449 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [cpuconfig.pm, cpu.pm] Subject: [pve-devel] [RFC qemu-server 3/9] api: add /cpu/model/* get endpoint X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Oct 2021 11:42:00 -0000 For custom models, this returns the saved configuration, for default models it returns the cputype, vendor and a list of flags that the guest OS will see when running with this CPU type (using the -list-flags QEMU parameter). For custom models it also includes the digest of the whole config, in case someone retrieved it to modify it with a PUT call afterwards. Signed-off-by: Stefan Reiter --- PVE/API2/Qemu/CPU.pm | 76 ++++++++++++++++++++++++++++++++++++- PVE/QemuServer/CPUConfig.pm | 7 ++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/PVE/API2/Qemu/CPU.pm b/PVE/API2/Qemu/CPU.pm index 610ffb9..9cc1d77 100644 --- a/PVE/API2/Qemu/CPU.pm +++ b/PVE/API2/Qemu/CPU.pm @@ -5,8 +5,10 @@ use warnings; use PVE::RESTHandler; use PVE::JSONSchema qw(get_standard_option); +use PVE::INotify; use PVE::QemuServer; use PVE::QemuServer::CPUConfig; +use PVE::Tools qw(run_command get_host_arch); use base qw(PVE::RESTHandler); @@ -49,7 +51,7 @@ __PACKAGE__->register_method({ }, }, }, - links => [ { rel => 'child', href => '{name}' } ], + links => [ { rel => 'child', href => 'model/{name}' } ], }, code => sub { my $rpcenv = PVE::RPCEnvironment::get(); @@ -144,4 +146,76 @@ __PACKAGE__->register_method({ return $retval; }}); +__PACKAGE__->register_method({ + name => 'info', + path => 'model/{cputype}', + method => 'GET', + description => 'Retrieve details about a specific CPU model.', + permissions => { + check => [ 'perm', '/nodes', ['Sys.Audit'] ], + }, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + cputype => { + type => 'string', + description => "Name of the CPU model to query. Prefix with" + . " '-custom' for custom models.", + }, + }, + }, + returns => { + type => 'object', + properties => PVE::QemuServer::CPUConfig::add_cpu_json_properties({ + vendor => { + type => 'string', + description => 'The CPU vendor reported to the guest OS. Only' + . ' relevant for default models.', + optional => 1, + }, + digest => get_standard_option('pve-config-digest'), + }), + }, + code => sub { + my ($param) = @_; + my $cputype = $param->{cputype}; + + if ($cputype =~ m/^custom-/) { + my $conf = PVE::QemuServer::CPUConfig::load_custom_model_conf(); + my $digest = $conf->{digest}; + my $retval = PVE::QemuServer::CPUConfig::get_custom_model($cputype); + $retval->{digest} = $digest; + return $retval; + } + + # this correctly errors in case $cputype is unknown + my $vendor = PVE::QemuServer::CPUConfig::get_cpu_vendor($cputype); + + my $retval = { + cputype => $cputype, + vendor => $vendor, + }; + + # for built-in models return all flags that QEMU assigns to this model + # by default (note that these flags might still differ very slightly + # with certain machine versions, but since this output is only intended + # for assisting a user in a GUI environment this should be fine) + my @flags; + my $qemu_binary = PVE::QemuServer::get_command_for_arch(get_host_arch()); + my $retcode = run_command([$qemu_binary, '-list-flags', '-cpu', $cputype], + outfunc => sub { @flags = split(/\s/, shift); }, noerr => 1); + + if ($retcode || !@flags) { + my $nodename = PVE::INotify::nodename(); + warn "warning: could not retrieve QEMU flags for built-in cpu type" + . " '$cputype'. Make sure node '$nodename' has the latest" + . " pve-qemu-kvm.\n"; + } else { + $retval->{flags} = join(";", map {"+$_"} @flags); + } + + return $retval; + }}); + 1; diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm index b9981c8..9be8022 100644 --- a/PVE/QemuServer/CPUConfig.pm +++ b/PVE/QemuServer/CPUConfig.pm @@ -320,6 +320,13 @@ sub is_custom_model { return $cputype =~ m/^custom-/; } +sub get_cpu_vendor { + my ($cputype) = @_; + my $retval = $cpu_vendor_list->{$cputype} or + die "Built-in CPU type '$cputype' does not exist\n"; + return $retval; +} + # Use this to get a single model in the format described by $cpu_fmt. # Allows names with and without custom- prefix. sub get_custom_model { -- 2.30.2