public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: David Riley <d.riley@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network v5 2/6] sdn: register api formats for zones and vnets
Date: Thu, 19 Nov 2026 13:47:27 +0100	[thread overview]
Message-ID: <20261119124731.84602-3-d.riley@proxmox.com> (raw)
In-Reply-To: <20261119124731.84602-1-d.riley@proxmox.com>

Register JSONSchema format validators for both SDN zones and VNets,
enabling the pool members API to verify these network identifiers.

Prepare for #7294 to enable schema validation of pool resources.

Signed-off-by: David Riley <d.riley@proxmox.com>
Reviewed-by: Daniel Kral <d.kral@proxmox.com>
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7294
---
 src/PVE/Network/SDN/VnetPlugin.pm   | 26 +++++++++++++++++++++++---
 src/PVE/Network/SDN/Zones/Plugin.pm | 26 +++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/src/PVE/Network/SDN/VnetPlugin.pm b/src/PVE/Network/SDN/VnetPlugin.pm
index 7a38457..b855827 100644
--- a/src/PVE/Network/SDN/VnetPlugin.pm
+++ b/src/PVE/Network/SDN/VnetPlugin.pm
@@ -16,14 +16,34 @@ PVE::Cluster::cfs_register_file(
     sub { __PACKAGE__->write_config(@_); },
 );
 
+my $sdn_vnet_id_pattern = '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]';
+my $vnet_min_length = 2;
+my $vnet_max_length = 8;
+
+sub pve_verify_sdn_vnet_id {
+    my ($vnet, $noerr) = @_;
+
+    my $len = length($vnet);
+
+    if ($vnet !~ m/^$sdn_vnet_id_pattern$/o || $len < $vnet_min_length || $len > $vnet_max_length) {
+        return undef if $noerr;
+        die "invalid SDN VNet '$vnet', must be $vnet_min_length-$vnet_max_length characters"
+            . " long, start with a letter, and contain only alphanumeric characters\n";
+    }
+    return $vnet;
+}
+
+PVE::JSONSchema::register_format('pve-sdn-vnet-id', \&pve_verify_sdn_vnet_id);
+
 PVE::JSONSchema::register_standard_option(
     'pve-sdn-vnet-id',
     {
         description => "The SDN vnet object identifier.",
         type => 'string',
-        pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]',
-        minLength => 2,
-        maxLength => 8,
+        format => 'pve-sdn-vnet-id',
+        pattern => $sdn_vnet_id_pattern,
+        minLength => $vnet_min_length,
+        maxLength => $vnet_max_length,
     },
 );
 
diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm
index f3844ff..c463d57 100644
--- a/src/PVE/Network/SDN/Zones/Plugin.pm
+++ b/src/PVE/Network/SDN/Zones/Plugin.pm
@@ -18,14 +18,34 @@ PVE::Cluster::cfs_register_file(
     sub { __PACKAGE__->write_config(@_); },
 );
 
+my $sdn_zone_id_pattern = '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]';
+my $zone_min_length = 2;
+my $zone_max_length = 8;
+
+sub pve_verify_sdn_zone_id {
+    my ($zone, $noerr) = @_;
+
+    my $len = length($zone);
+
+    if ($zone !~ m/^$sdn_zone_id_pattern$/o || $len < $zone_min_length || $len > $zone_max_length) {
+        return undef if $noerr;
+        die "invalid SDN zone '$zone', must be $zone_min_length-$zone_max_length characters long,"
+            . " start with a letter, and contain only alphanumeric characters\n";
+    }
+    return $zone;
+}
+
+PVE::JSONSchema::register_format('pve-sdn-zone-id', \&pve_verify_sdn_zone_id);
+
 PVE::JSONSchema::register_standard_option(
     'pve-sdn-zone-id',
     {
         description => "The SDN zone object identifier.",
         type => 'string',
-        pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]',
-        minLength => 2,
-        maxLength => 8,
+        format => 'pve-sdn-zone-id',
+        pattern => $sdn_zone_id_pattern,
+        minLength => $zone_min_length,
+        maxLength => $zone_max_length,
     },
 );
 
-- 
2.47.3





  parent reply	other threads:[~2026-11-19 12:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:47 [PATCH access-control/manager/network v5 0/6] fix #7294: pool: add SDN VNets as pool members David Riley
2026-11-19 12:47 ` [PATCH pve-access-control v5 1/6] rpcenv: allow SDN.Allocate to modify permissions on SDN paths David Riley
2026-11-19 12:47 ` David Riley [this message]
2026-11-19 12:47 ` [PATCH pve-network v5 3/6] fix #7294: sdn: vnet: update pool members on VNet zone change and deletion David Riley
2026-11-19 12:47 ` [PATCH pve-manager v5 4/6] ui: replace var with let to match style guide for variable declaration David Riley
2026-11-19 12:47 ` [PATCH pve-manager v5 5/6] fix #7294: api: pool: add SDN VNets as pool members David Riley
2026-11-19 12:47 ` [PATCH pve-manager v5 6/6] fix #7294: ui: " 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=20261119124731.84602-3-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 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