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 7CA0B7A007 for ; Thu, 28 Oct 2021 13:42:29 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 730B51F95C 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 6E3861F913 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 462F5469B5 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:43 +0200 Message-Id: <20211028114150.3245864-3-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.453 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. [cpu.pm] Subject: [pve-devel] [RFC qemu-server 2/9] api: add recognized-flags and supported-flags endpoints 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:29 -0000 For supporting a GUI to easily create custom CPU models based on cluster CPU availability. Signed-off-by: Stefan Reiter --- PVE/API2/Qemu/CPU.pm | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/PVE/API2/Qemu/CPU.pm b/PVE/API2/Qemu/CPU.pm index b0bb32d..610ffb9 100644 --- a/PVE/API2/Qemu/CPU.pm +++ b/PVE/API2/Qemu/CPU.pm @@ -5,6 +5,7 @@ use warnings; use PVE::RESTHandler; use PVE::JSONSchema qw(get_standard_option); +use PVE::QemuServer; use PVE::QemuServer::CPUConfig; use base qw(PVE::RESTHandler); @@ -58,4 +59,89 @@ __PACKAGE__->register_method({ return PVE::QemuServer::CPUConfig::get_cpu_models($include_custom); }}); +__PACKAGE__->register_method({ + name => 'recognized-flags', + path => 'recognized-flags', + method => 'GET', + description => 'List all CPU flags recognized by QEMU on this node.', + permissions => { + check => [ 'perm', '/nodes', ['Sys.Audit'] ], + }, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + }, + }, + returns => { + type => 'array', + items => { + type => 'string', + }, + }, + code => sub { + return PVE::QemuServer::query_understood_cpu_flags(); + }}); + +__PACKAGE__->register_method({ + name => 'supported-flags', + path => 'supported-flags', + method => 'GET', + description => 'List all CPU flags actually supported on each node.', + permissions => { + check => [ 'perm', '/nodes', ['Sys.Audit'] ], + }, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + }, + }, + returns => { + type => 'array', + items => { + type => 'object', + properties => { + node => get_standard_option('pve-node'), + kvm => { + type => 'array', + items => { + type => 'string', + }, + }, + tcg => { + type => 'array', + items => { + type => 'string', + }, + }, + }, + }, + }, + code => sub { + my $retval = []; + + # Note: These get_node_kv calls can potentially race if the KV store + # gets updated inbetween. This is okay, since it is very unlikely to + # happen (these entries rarely change), and this API call should only + # be used to inform a user anyway + my $flags_kvm = PVE::Cluster::get_node_kv("cpuflags-kvm"); + my $flags_tcg = PVE::Cluster::get_node_kv("cpuflags-tcg"); + + for my $node (keys %$flags_kvm) { + next if !exists $flags_tcg->{$node}; + + my @split_kvm = split(' ', $flags_kvm->{$node}); + my @split_tcg = split(' ', $flags_tcg->{$node}); + + push @$retval, { + node => $node, + kvm => \@split_kvm, + tcg => \@split_tcg, + }; + } + + return $retval; + }}); + 1; -- 2.30.2