[pve-devel] [RFC qemu-server 2/9] api: add recognized-flags and supported-flags endpoints

Stefan Reiter s.reiter at proxmox.com
Thu Oct 28 13:41:43 CEST 2021


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

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






More information about the pve-devel mailing list