From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 2DDB31FF0E0 for ; Thu, 09 Jul 2026 11:23:12 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 28F97217C5; Thu, 09 Jul 2026 11:20:09 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v2 18/27] sdn: microseg: add name regex matcher Date: Thu, 9 Jul 2026 11:18:43 +0200 Message-ID: <20260709091852.538885-19-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260709091852.538885-1-h.laimer@proxmox.com> References: <20260709091852.538885-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783588746664 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.294 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) 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: 2RJB6AFPGSRFNP6EDS4D6HZ6KBTLCEIJ X-Message-ID-Hash: 2RJB6AFPGSRFNP6EDS4D6HZ6KBTLCEIJ X-MailFrom: h.laimer@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: Expose the regex matcher through the assignment API: a 'regexassignment' type with a name_regex property gated to it, and include each guest's name in the inventory the matcher expands against. Signed-off-by: Hannes Laimer --- src/PVE/API2/Network/SDN/Microseg.pm | 8 +++++++- src/PVE/Network/SDN/Microseg.pm | 23 +++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/PVE/API2/Network/SDN/Microseg.pm b/src/PVE/API2/Network/SDN/Microseg.pm index fc1e4ac..85e3194 100644 --- a/src/PVE/API2/Network/SDN/Microseg.pm +++ b/src/PVE/API2/Network/SDN/Microseg.pm @@ -97,7 +97,13 @@ __PACKAGE__->register_method({ id => { type => 'string', description => 'Object identifier.' }, type => { type => 'string', - enum => ['group', 'rule', 'guestassignment', 'tagassignment'], + enum => [ + 'group', + 'rule', + 'guestassignment', + 'tagassignment', + 'regexassignment', + ], }, state => get_standard_option('pve-sdn-config-state'), pending => { diff --git a/src/PVE/Network/SDN/Microseg.pm b/src/PVE/Network/SDN/Microseg.pm index f000ce6..57aa40e 100644 --- a/src/PVE/Network/SDN/Microseg.pm +++ b/src/PVE/Network/SDN/Microseg.pm @@ -39,7 +39,7 @@ cfs_register_file('sdn/microseg.cfg', \&parse_microseg_config, \&write_microseg_ # The stored section types of the assignment family, one per matcher kind. The API presents them # under a single 'assignment' endpoint that discriminates on the 'type' property (storage splits # them so each section carries only its matcher's fields). Add a new matcher's stored type here. -our $ASSIGNMENT_TYPES = ['guestassignment', 'tagassignment']; +our $ASSIGNMENT_TYPES = ['guestassignment', 'tagassignment', 'regexassignment']; sub parse_microseg_config { my ($filename, $raw) = @_; @@ -185,7 +185,8 @@ sub assignment_properties { type => 'string', enum => $ASSIGNMENT_TYPES, description => "The matcher kind: 'guestassignment' binds a specific guest," - . " 'tagassignment' binds every guest carrying the matched tags.", + . " 'tagassignment' binds every guest carrying the matched tags," + . " 'regexassignment' binds every guest whose name matches a regex.", }; $properties->{vmid} = get_standard_option( 'pve-vmid', @@ -217,6 +218,15 @@ sub assignment_properties { description => "How tags match: any (the guest shares a listed tag), all" . " (the guest carries every listed tag), or exact (its tags equal the listed set).", }; + $properties->{name_regex} = { + type => 'string', + maxLength => 1024, + optional => 1, + 'type-property' => 'type', + 'instance-types' => ['regexassignment'], + description => + "Regex matcher: a regular expression matched against each guest's name.", + }; $properties->{iface} = { type => 'integer', minimum => 0, @@ -231,11 +241,11 @@ sub assignment_properties { # The guest inventory assignments are expanded against at render time: every guest, with its tags # and the netN indices it currently has. Pulled cluster-wide from the pmxcfs in-memory index in a -# single call (faster than parsing each config). All guests are included (not just tagged -# ones), since a guest matcher with no iface needs the guest's NIC list too. Returns an arrayref of -# { vmid, tags => [...], nics => [...] } for the Rust render / realized expansion. +# single call. All guests are included, since a guest matcher with no iface needs the guest's NIC +# list too. Returns an arrayref of { vmid, name, tags => [...], nics => [...] } for the Rust +# render / realized expansion. sub guest_inventory { - my $props = ['tags', map { "net$_" } 0 .. 31]; + my $props = ['tags', 'name', 'hostname', map { "net$_" } 0 .. 31]; my $by_vmid = PVE::Cluster::get_guest_config_properties($props); my $inventory = []; @@ -250,6 +260,7 @@ sub guest_inventory { push @$inventory, { vmid => $vmid + 0, + name => $guest->{name} // $guest->{hostname}, tags => \@tags, nics => [map { $_ + 0 } @nics], }; -- 2.47.3