]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/JSONSchema.pm
PVE::CalendarEvent - register format 'pve-calendar-event'
[pve-common.git] / src / PVE / JSONSchema.pm
index 936c3cfa7feeea0527ef19e963858374c02db99f..02aa2ab1d0228644b3929ad2541998e836ae4606 100644 (file)
@@ -4,6 +4,8 @@ use strict;
 use warnings;
 use Storable; # for dclone
 use Getopt::Long;
+use Encode::Locale;
+use Encode;
 use Devel::Cycle -quiet; # todo: remove?
 use PVE::Tools qw(split_list $IPV6RE $IPV4RE);
 use PVE::Exception qw(raise);
@@ -429,6 +431,37 @@ PVE::JSONSchema::register_standard_option('pve-startup-order', {
     typetext => '[[order=]\d+] [,up=\d+] [,down=\d+] ',
 });
 
+my $replicate_fmt = {
+    target => {
+       default_key => 1,
+       description => "Storage replication target node.",
+       type => 'string', format => 'pve-node',
+       format_description => "node",
+    },
+    rate => {
+       description => "Rate limit in mbps (megabytes per second) as floating point number.",
+       type => 'number',
+       minimum => 1,
+       optional => 1,
+    },
+    interval => {
+       description => "Storage replication sync interval in minutes. If set to zero replication is disabled.",
+       type => 'integer',
+       minimum => 0,
+       maximum => 1440,
+       default => 15,
+       optional => 1,
+    },
+};
+
+PVE::JSONSchema::register_format('pve-replicate', $replicate_fmt);
+
+PVE::JSONSchema::register_standard_option('pve-replicate', {
+    description => "Storage replication settings.",
+    type => 'string', format => 'pve-replicate',
+    optional => 1,
+});
+
 sub check_format {
     my ($format, $value, $path) = @_;
 
@@ -1349,7 +1382,22 @@ sub get_options {
        }
     }
 
-    $opts = PVE::Tools::decode_utf8_parameters($opts);
+    # decode after Getopt as we are not sure how well it handles unicode
+    foreach my $p (keys %$opts) {
+       if (!ref($opts->{$p})) {
+           $opts->{$p} = decode('locale', $opts->{$p});
+       } elsif (ref($opts->{$p}) eq 'ARRAY') {
+           my $tmp = [];
+           foreach my $v (@{$opts->{$p}}) {
+               push @$tmp, decode('locale', $v);
+           }
+           $opts->{$p} = $tmp;
+       } elsif (ref($opts->{$p}) eq 'SCALAR') {
+           $opts->{$p} = decode('locale', $$opts->{$p});
+       } else {
+           raise("decoding options failed, unknown reference\n", code => HTTP_BAD_REQUEST);
+       }
+    }
 
     foreach my $p (keys %$opts) {
        if (my $pd = $schema->{properties}->{$p}) {