[pve-devel] [PATCH v5 pve-common 5/5] json schema : add pve-network-id

Alexandre Derumier aderumier at odiso.com
Wed Apr 3 15:39:20 CEST 2019


fix me : fix parsing of vnet(\d+) different than other plugins
---
 src/PVE/JSONSchema.pm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index f0fc2aa..1b45398 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -79,6 +79,11 @@ register_standard_option('pve-storage-id', {
     type => 'string', format => 'pve-storage-id',
 }); 
 
+register_standard_option('pve-network-id', {
+    description => "The Network object identifier.",
+    type => 'string', format => 'pve-network-id',
+}); 
+
 register_standard_option('pve-config-digest', {
     description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
     type => 'string',
@@ -187,6 +192,19 @@ sub parse_storage_id {
     return $storeid;
 }
 
+PVE::JSONSchema::register_format('pve-network-id', \&parse_network_id);
+sub parse_network_id {
+    my ($networkid, $noerr) = @_;
+
+   #fixme for vnet
+#    if ($vnetid !~ m/^vnet(\d+)$/i) {
+
+    if ($networkid !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
+	return undef if $noerr;
+	die "network object ID '$networkid' contains illegal characters\n";
+    }
+    return $networkid;
+}
 
 register_format('pve-vmid', \&pve_verify_vmid);
 sub pve_verify_vmid {
-- 
2.11.0




More information about the pve-devel mailing list