]> git.proxmox.com Git - pve-common.git/blobdiff - data/PVE/JSONSchema.pm
register new standard option pve-config-digest
[pve-common.git] / data / PVE / JSONSchema.pm
index 881120769778d944ef706357244ef0faaff1d8a2..3e0fd52c13f54d0eab19e49dac5eece2129c7c5b 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 use Storable; # for dclone
 use Getopt::Long;
 use Devel::Cycle -quiet; # todo: remove?
-use PVE::Tools qw(split_list);
+use PVE::Tools qw(split_list $IPV6RE $IPV4RE);
 use PVE::Exception qw(raise);
 use HTTP::Status qw(:constants);
 use Net::IP qw(:PROC);
@@ -76,6 +76,13 @@ PVE::JSONSchema::register_standard_option('pve-storage-id', {
     type => 'string', format => 'pve-storage-id',
 }); 
 
+PVE::JSONSchema::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',
+    optional => 1,
+    maxLength => 40, # sha1 hex digest lenght is 40
+});
+
 my $format_list = {};
 
 sub register_format {
@@ -191,6 +198,20 @@ sub pve_verify_ipv4mask {
     return $mask;
 }
 
+register_format('CIDR', \&pve_verify_cidr);
+sub pve_verify_cidr {
+    my ($cidr, $noerr) = @_;
+
+    if ($cidr =~ m!^(?:$IPV4RE)(?:/(\d+))$! && ($1 > 7) &&  ($1 < 32)) {
+       return $cidr;
+    } elsif ($cidr =~ m!^(?:$IPV6RE)(?:/(\d+))$! && ($1 > 7) &&  ($1 <= 120)) {
+       return $cidr;
+    }
+
+    return undef if $noerr;
+    die "value does not look like a valid CIDR network\n";
+}
+
 register_format('email', \&pve_verify_email);
 sub pve_verify_email {
     my ($email, $noerr) = @_;