public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager v2 3/4] api: pve: add VM-specific CPU flags endpoint
Date: Mon, 30 Nov 2026 15:10:53 +0100	[thread overview]
Message-ID: <20261130141054.556314-4-a.bied-charreton@proxmox.com> (raw)
In-Reply-To: <20261130141054.556314-1-a.bied-charreton@proxmox.com>

Fetch VM-specific CPU flags from the node so the CPU editor can stay in
sync with qemu-server instead of hardcoding the list that misses newer
ones like nested-virt.

Needs Resource.Audit on anything below the remote, since PVE shows that
list to any logged-in user.

Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
 server/src/api/pve/node.rs | 64 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 61 insertions(+), 3 deletions(-)

diff --git a/server/src/api/pve/node.rs b/server/src/api/pve/node.rs
index 5c7683bc..234d2939 100644
--- a/server/src/api/pve/node.rs
+++ b/server/src/api/pve/node.rs
@@ -1,7 +1,9 @@
 use anyhow::{Context, Error};
 
 use proxmox_access_control::CachedUserInfo;
-use proxmox_router::{Permission, Router, RpcEnvironment, SubdirMap, list_subdirs_api_method};
+use proxmox_router::{
+    Permission, Router, RpcEnvironment, SubdirMap, http_bail, list_subdirs_api_method,
+};
 use proxmox_schema::api;
 use proxmox_sortable_macro::sortable;
 
@@ -313,8 +315,10 @@ const QEMU_CAPABILITIES_ROUTER: Router = Router::new()
     .get(&list_subdirs_api_method!(QEMU_CAPABILITIES_SUBDIRS))
     .subdirs(QEMU_CAPABILITIES_SUBDIRS);
 
-const QEMU_CAPABILITIES_SUBDIRS: SubdirMap =
-    &[("cpu", &Router::new().get(&API_METHOD_QEMU_CPU_CAPABILITIES))];
+const QEMU_CAPABILITIES_SUBDIRS: SubdirMap = &[
+    ("cpu", &Router::new().get(&API_METHOD_QEMU_CPU_CAPABILITIES)),
+    ("cpu-flags", &Router::new().get(&API_METHOD_QEMU_CPU_FLAGS)),
+];
 
 #[api(
     input: {
@@ -350,3 +354,57 @@ async fn qemu_cpu_capabilities(
         .await
         .map_err(Into::into)
 }
+
+#[api(
+    input: {
+        properties: {
+            remote: { schema: REMOTE_ID_SCHEMA },
+            node: { schema: NODE_SCHEMA },
+            accel: {
+                type: pve_api_types::QemuCpuFlagsAccel,
+                optional: true,
+            },
+            arch: {
+                type: pve_api_types::ClusterResourceHostArch,
+                optional: true,
+            },
+        },
+    },
+    access: {
+        permission: &Permission::Anybody,
+        description: "Requires `Resource.Audit` on anything below the remote.",
+    },
+    returns: {
+        type: Array,
+        description: "A list of VM-specific CPU flags available on the remote.",
+        items: {
+            type: pve_api_types::QemuCpuFlag,
+        }
+    }
+)]
+/// List the VM-specific CPU flags available on a remote.
+async fn qemu_cpu_flags(
+    remote: String,
+    node: String,
+    accel: Option<pve_api_types::QemuCpuFlagsAccel>,
+    arch: Option<pve_api_types::ClusterResourceHostArch>,
+    rpcenv: &mut dyn RpcEnvironment,
+) -> Result<Vec<pve_api_types::QemuCpuFlag>, Error> {
+    let auth_id: Authid = rpcenv
+        .get_auth_id()
+        .context("no authid available")?
+        .parse()?;
+    if !CachedUserInfo::new()?.any_privs_below(
+        &auth_id,
+        &["resource", &remote],
+        PRIV_RESOURCE_AUDIT,
+    )? {
+        http_bail!(FORBIDDEN, "user has no access to this remote");
+    }
+
+    let client = super::connect_to_remote_for_node(&remote, &node)?;
+    client
+        .qemu_cpu_flags(&node, accel, arch)
+        .await
+        .map_err(Into::into)
+}
-- 
2.47.3





  parent reply	other threads:[~2026-11-30 14:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:10 [PATCH datacenter-manager/proxmox{,-yew-comp}/qemu-server v2 0/4] load VM-specific CPU flags from the remote Arthur Bied-Charreton
2026-11-30 14:10 ` [PATCH qemu-server v2 1/4] api: cpu flags: proxy the request to the given node Arthur Bied-Charreton
2026-11-30 14:10 ` [PATCH proxmox v2 2/4] pve-api-types: add VM-specific CPU flags endpoint Arthur Bied-Charreton
2026-11-30 14:10 ` Arthur Bied-Charreton [this message]
2026-11-30 14:10 ` [PATCH proxmox-yew-comp v2 4/4] qemu: cpu flags: load the CPU flags from the node Arthur Bied-Charreton

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=20261130141054.556314-4-a.bied-charreton@proxmox.com \
    --to=a.bied-charreton@proxmox.com \
    --cc=pdm-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal