[pdm-devel] [PATCH proxmox 2/3] pve-api-types: add regex for both storage- and bridge-pair

Hannes Laimer h.laimer at proxmox.com
Tue Oct 21 15:50:16 CEST 2025


These are used for target storage and bridge mappings in remote
migrations. For the list items we don't really need a verifier function
so remove them and add regexes instead.

What this is not doing is check for uniqueness of mappings in the list,
but that is not really possible. Since we can't currently have verifiers
on fields that are not strings.

Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
 pve-api-types/generate.pl            | 11 +++++++----
 pve-api-types/src/types/verifiers.rs | 10 ----------
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/pve-api-types/generate.pl b/pve-api-types/generate.pl
index 75729b3c..9ea9aa4f 100644
--- a/pve-api-types/generate.pl
+++ b/pve-api-types/generate.pl
@@ -31,6 +31,9 @@ Schema2Rust::init_api($pve_api->{root}, \&lookup_format);
 # From JSONSchema.pm, but we can't use perl-re directly, particularly `qr//`...
 my $CONFIGID_RE = '^(?i:[a-z][a-z0-9_-]+)$';
 
+my $STORAGEID_RE = '(?i:[a-z][a-z0-9\-_.]*[a-z0-9])';
+my $BRIDGEID_RE = '[-_.\w\d]+';
+
 # Disable `#[api]` generation for now, it's incomplete/untested.
 #$Schema2Rust::API = 0;
 
@@ -41,7 +44,7 @@ Schema2Rust::register_format('ipv4mask' => { code => 'verifiers::verify_ipv4_mas
 Schema2Rust::register_format('mac-addr' => { regex => '^(?i)[a-f0-9][02468ace](?::[a-f0-9]{2}){5}$' });
 ## Schema2Rust::register_format('pve-acme-alias' => { code => 'verify_pve_acme_alias' });
 ## Schema2Rust::register_format('pve-acme-domain' => { code => 'verify_pve_acme_domain' });
-Schema2Rust::register_format('pve-bridge-id' => { regex => '^[-_.\w\d]+$' });
+Schema2Rust::register_format('pve-bridge-id' => { regex => '^'.$BRIDGEID_RE.'$' });
 Schema2Rust::register_format('pve-configid' => { regex => $CONFIGID_RE });
 ## Schema2Rust::register_format('pve-groupid' => { code => 'verify_pve_groupid' });
 Schema2Rust::register_format('pve-userid' => { code => 'verify_pve_userid' });
@@ -59,7 +62,7 @@ Schema2Rust::register_format('pve-qm-bootdev' => { unchecked => 1 });
 Schema2Rust::register_format('pve-qm-bootdisk' => { regex => '^(ide|sata|scsi|virtio|efidisk|tpmstate)\d+$' });
 Schema2Rust::register_format('pve-qm-usb-device' => { unchecked => 1 });
 Schema2Rust::register_format('pve-startup-order' => { unchecked => 1 });
-Schema2Rust::register_format('pve-storage-id' => { regex => '^(?i:[a-z][a-z0-9\-_.]*[a-z0-9])$' });
+Schema2Rust::register_format('pve-storage-id' => { regex => '^'.$STORAGEID_RE.'$' });
 Schema2Rust::register_format('pve-storage-content' => { type => 'StorageContent' });
 Schema2Rust::register_format('pve-tag' => { regex => '^(?i)[a-z0-9_][a-z0-9_\-+.]*$' });
 Schema2Rust::register_format('pve-volume-id' => { code => 'verifiers::verify_volume_id' });
@@ -75,8 +78,8 @@ Schema2Rust::register_format('lxc-ip-with-ll-iface' => { code => 'verifiers::ver
 Schema2Rust::register_format('pve-ct-timezone' => { regex => '^.*/.*$' });
 Schema2Rust::register_format('pve-lxc-dev-string' => { code => 'verifiers::verify_pve_lxc_dev_string' });
 ##
-Schema2Rust::register_format('storage-pair' => { code => 'verifiers::verify_storage_pair' });
-Schema2Rust::register_format('bridge-pair' => { code => 'verifiers::verify_bridge_pair' });
+Schema2Rust::register_format('storage-pair' => { regex => '^'.$STORAGEID_RE.':'.$STORAGEID_RE.'|'.$STORAGEID_RE.'|1$' });
+Schema2Rust::register_format('bridge-pair' => { regex => '^'.$BRIDGEID_RE.':'.$BRIDGEID_RE.'|'.$BRIDGEID_RE.'|1$' });
 
 Schema2Rust::register_format('pve-task-status-type' => { regex => '^(?i:ok|error|warning|unknown)$' });
 
diff --git a/pve-api-types/src/types/verifiers.rs b/pve-api-types/src/types/verifiers.rs
index caefba1a..092893b3 100644
--- a/pve-api-types/src/types/verifiers.rs
+++ b/pve-api-types/src/types/verifiers.rs
@@ -194,16 +194,6 @@ pub fn verify_ip_with_ll_iface(s: &str) -> Result<(), Error> {
     verify_ip(s)
 }
 
-pub fn verify_storage_pair(_s: &str) -> Result<(), Error> {
-    // FIXME: Implement this!
-    Ok(())
-}
-
-pub fn verify_bridge_pair(_s: &str) -> Result<(), Error> {
-    // FIXME: Implement this!
-    Ok(())
-}
-
 pub fn verify_pve_lxc_dev_string(s: &str) -> Result<(), Error> {
     if !s.starts_with("/dev") || s.ends_with("/..") || s.contains("/..") {
         bail!("not a valid device string");
-- 
2.47.3





More information about the pdm-devel mailing list