From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 87C101FF0AB for ; Wed, 09 Sep 2026 18:30:38 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5CD2521647; Wed, 09 Sep 2026 18:30:35 +0200 (CEST) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager 1/3] api: add mappings to resources endpoint Date: Wed, 9 Sep 2026 18:29:29 +0200 Message-ID: <20260909163013.444378-2-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260909163013.444378-1-j.theisen@proxmox.com> References: <20260909163013.444378-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788971419818 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.436 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: C7NXWR63IP6NVU5D4NFGXF4AWN35RHYW X-Message-ID-Hash: C7NXWR63IP6NVU5D4NFGXF4AWN35RHYW X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Similar to the SDN zones this patch adds the USB, PCI and directory mappings to the resources endpoint of the API. It adds a new type 'mapping' for this and distinguishes the mappings with 'mapping-type' in the returned object. This is needed to allow the permissions tab to gather the IDs of the mappings for the paths list. Signed-off-by: Jonas Theisen --- PVE/API2/Cluster.pm | 58 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm index 4e5efbfd..3df03411 100644 --- a/PVE/API2/Cluster.pm +++ b/PVE/API2/Cluster.pm @@ -272,7 +272,7 @@ __PACKAGE__->register_method({ type => 'string', description => 'Resource type.', optional => 1, - enum => ['vm', 'storage', 'node', 'sdn'], + enum => ['vm', 'storage', 'node', 'sdn', 'mapping'], }, }, }, @@ -288,8 +288,17 @@ __PACKAGE__->register_method({ type => { description => "Resource type.", type => 'string', - enum => - ['node', 'storage', 'pool', 'qemu', 'lxc', 'openvz', 'sdn', 'network'], + enum => [ + 'node', + 'storage', + 'pool', + 'qemu', + 'lxc', + 'openvz', + 'sdn', + 'network', + 'mapping', + ], }, status => { description => "Resource type dependent status.", @@ -503,6 +512,17 @@ __PACKAGE__->register_method({ default => 'x86_64', optional => 1, }, + mapping => { + description => "The name of the mapping (for type 'mapping')", + type => "string", + optional => 1, + }, + 'mapping-type' => { + description => "The type of the mapping (for type 'mapping')", + type => "string", + enum => ["pci", "usb", "dir"], + optional => 1, + }, }, }, }, @@ -723,6 +743,38 @@ __PACKAGE__->register_method({ } } + if (!$param->{type} || $param->{type} eq 'mapping') { + my $can_see_mapping_privs = ['Mapping.Modify', 'Mapping.Use', 'Mapping.Audit']; + + foreach my $mapping_type ('pci', 'usb', 'dir') { + my $cfg = {}; + + if ($mapping_type eq 'pci') { + $cfg = PVE::Mapping::PCI::config(); + } elsif ($mapping_type eq 'usb') { + $cfg = PVE::Mapping::USB::config(); + } elsif ($mapping_type eq 'dir') { + $cfg = PVE::Mapping::Dir::config(); + } + + for my $id (keys $cfg->{ids}->%*) { + next + if !($rpcenv->check( + $authuser, "/mapping/$mapping_type/$id", $can_see_mapping_privs, 1, + )); + next if !$cfg->{ids}->{$id}; + + push @$res, + { + id => "mapping/$mapping_type/$id", + mapping => $id, + 'mapping-type' => $mapping_type, + type => 'mapping', + }; + } + } + } + return $res; }, }); -- 2.47.3