From: David Riley <d.riley@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-access-control v3 05/12] fix #7294: acl: pool: add helpers to remove and migrate pool VNets
Date: Fri, 24 Jul 2026 16:25:21 +0200 [thread overview]
Message-ID: <20260724142528.109453-6-d.riley@proxmox.com> (raw)
In-Reply-To: <20260724142528.109453-1-d.riley@proxmox.com>
Add helper methods to keep network pool entries in sync with the SDN
configuration.
Drop stale references from the pool configuration when a VNet is
deleted. When a VNet migrates across zones, update the existing pool
entries to point to the new zone path.
Suggested-by: Daniel Kral <d.kral@proxmox.com>
Signed-off-by: David Riley <d.riley@proxmox.com>
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7294
---
src/PVE/AccessControl.pm | 104 +++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm
index 50fdb2d..42fa709 100644
--- a/src/PVE/AccessControl.pm
+++ b/src/PVE/AccessControl.pm
@@ -2041,6 +2041,110 @@ sub remove_vm_from_pool {
lock_user_config($delVMfromPoolFn, "pool cleanup for VM $vmid failed");
}
+sub remove_vnets_from_pool {
+ my ($paths) = @_;
+
+ my $del_vnet_from_pool_fn = sub {
+ my $usercfg = cfs_read_file("user.cfg");
+ my $modified = 0;
+
+ for my $pool (keys $usercfg->{pools}->%*) {
+ my $pool_cfg = $usercfg->{pools}->{$pool};
+
+ my @to_delete = ();
+
+ for my $net_key (keys $pool_cfg->{network}->%*) {
+ for my $path (@$paths) {
+ my (undef, $zone, $vnet) = split('/', $path);
+ my $network_key = "vnet/$zone/$vnet";
+
+ if ($net_key =~ m!^\Q$network_key\E(?:/(?:[0-9]+|\*))?$!) {
+ push(@to_delete, $net_key);
+ last; # match skip ahead
+ }
+ }
+ }
+
+ if (@to_delete) {
+ for my $del_key (@to_delete) {
+ delete $pool_cfg->{network}->{$del_key};
+ }
+ $modified = 1;
+ }
+
+ }
+ if ($modified) {
+ cfs_write_file("user.cfg", $usercfg);
+ }
+ };
+
+ lock_user_config($del_vnet_from_pool_fn, "pool cleanup for VNet failed");
+}
+
+sub migrate_vnet_zone_in_pool {
+ my ($move_paths) = @_;
+
+ my $update_vnet_zone_fn = sub {
+ my $usercfg = cfs_read_file("user.cfg");
+ my $modified = 0;
+
+ my %move_map = ();
+ for my $move ($move_paths->@*) {
+ my $src_key = $move->{src_path};
+ my $dest_key = $move->{dest_path};
+
+ $src_key =~ s!^zones/!vnet/!;
+ $dest_key =~ s!^zones/!vnet/!;
+
+ if ($src_key ne $dest_key) {
+ $move_map{$src_key} = $dest_key;
+ }
+
+ }
+
+ for my $pool (keys $usercfg->{pools}->%*) {
+ my $pool_cfg = $usercfg->{pools}->{$pool};
+
+ my @to_delete = ();
+ my %to_add = ();
+
+ for my $net_key (sort keys $pool_cfg->{network}->%*) {
+ if ($net_key =~ m!^(vnet/[^/]+/[^/]+)(?:/([0-9]+|\*))?$!) {
+ my $base_key = $1;
+ my $vlan = $2;
+
+ if (my $new_base = $move_map{$base_key}) {
+ push(@to_delete, $net_key);
+
+ my $target_key = $new_base;
+ $target_key .= "/$vlan" if defined($vlan);
+
+ $to_add{$target_key} = $pool_cfg->{network}->{$net_key};
+ }
+ }
+ }
+
+ if (@to_delete || keys %to_add) {
+ for my $delete_key (@to_delete) {
+ delete $pool_cfg->{network}->{$delete_key};
+ }
+
+ for my $add_key (sort keys %to_add) {
+ $pool_cfg->{network}->{$add_key} = $to_add{$add_key};
+ }
+
+ $modified = 1;
+ }
+ }
+
+ if ($modified) {
+ cfs_write_file("user.cfg", $usercfg);
+ }
+ };
+
+ lock_user_config($update_vnet_zone_fn, "pool update for VNets failed");
+}
+
sub remove_sdn_resource_access {
my ($paths) = @_; # [ 'zones/<zone>', 'zones/<zone>/<vnet>' ]
--
2.47.3
next prev parent reply other threads:[~2026-07-24 14:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 14:25 [PATCH access-control/cluster/common/manager/network/proxmox-widget-toolkit/qemu-server v3 00/12] fix #7294: pool: add SDN VNets as pool members David Riley
2026-07-24 14:25 ` [PATCH pve-common v3 01/12] tools: add helpers for version comparison David Riley
2026-07-24 14:25 ` [PATCH qemu-server v3 02/12] helpers: drop local version helpers in favor of pve-common David Riley
2026-07-24 14:25 ` [PATCH pve-cluster v3 03/12] cluster: helpers: add cluster-wide version assertion David Riley
2026-07-24 14:25 ` [PATCH pve-access-control v3 04/12] fix #7294: acl: pool: add SDN VNets as pool members David Riley
2026-07-24 14:25 ` David Riley [this message]
2026-07-24 14:25 ` [PATCH pve-access-control v3 06/12] readme: document " David Riley
2026-07-24 14:25 ` [PATCH pve-network v3 07/12] sdn: register api formats for zones and vnets David Riley
2026-07-24 14:25 ` [PATCH pve-network v3 08/12] fix #7294: sdn: vnet: update pool members on vnet migration and deletion David Riley
2026-07-24 14:25 ` [PATCH pve-manager v3 09/12] ui: replace var with let to match style guide for variable declaration David Riley
2026-07-24 14:25 ` [PATCH pve-manager v3 10/12] fix #7294: api: pool: add SDN VNets as pool members David Riley
2026-07-24 14:25 ` [PATCH pve-manager v3 11/12] fix #7294: ui: " David Riley
2026-07-24 14:25 ` [PATCH proxmox-widget-toolkit v3 12/12] fix #7294: css: theme: add opacity override for pool VNet icon David Riley
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=20260724142528.109453-6-d.riley@proxmox.com \
--to=d.riley@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.