all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC qemu-server 2/9] api: add recognized-flags and supported-flags endpoints
Date: Thu, 28 Oct 2021 13:41:43 +0200	[thread overview]
Message-ID: <20211028114150.3245864-3-s.reiter@proxmox.com> (raw)
In-Reply-To: <20211028114150.3245864-1-s.reiter@proxmox.com>

For supporting a GUI to easily create custom CPU models based on cluster
CPU availability.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
 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





  parent reply	other threads:[~2021-10-28 11:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28 11:41 [pve-devel] [RFC 0/9] Unfinished: Custom CPU type API and GUI Stefan Reiter
2021-10-28 11:41 ` [pve-devel] [RFC pve-qemu 1/9] Add -list-flags command line option Stefan Reiter
2021-10-28 11:41 ` Stefan Reiter [this message]
2021-10-28 11:41 ` [pve-devel] [RFC qemu-server 3/9] api: add /cpu/model/* get endpoint Stefan Reiter
2021-10-28 11:41 ` [pve-devel] [RFC qemu-server 4/9] api: add /cpu/model/* get/create/delete/update endpoints Stefan Reiter
2021-10-28 11:41 ` [pve-devel] [RFC manager 5/9] gui: VMCPUFlagSelector: fix unknownFlags behaviour Stefan Reiter
2021-10-28 11:41 ` [pve-devel] [RFC manager 6/9] gui: CPUModelSelector: fix dirty state on default Stefan Reiter
2021-10-28 11:41 ` [pve-devel] [RFC manager 7/9] gui: CPUModelSelector: add 'allowCustom' Stefan Reiter
2021-10-28 11:41 ` [pve-devel] [RFC manager 8/9] gui: add basic custom CPU model editor Stefan Reiter
2021-10-28 11:41 ` [pve-devel] [RFC manager 9/9] Initial attempt at CPU flag editor for custom models Stefan Reiter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211028114150.3245864-3-s.reiter@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal