X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2FPVE%2FJSONSchema.pm;h=f42519cbfe26ee3f91cf1fbacd53323ea1e5876f;hb=c70c3bbc838ecca0249071a294cd64e66967566d;hp=3e0fd52c13f54d0eab19e49dac5eece2129c7c5b;hpb=b51b16e6f58de4cb385bd461d97866b3d94c93ec;p=pve-common.git diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 3e0fd52..f42519c 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -37,7 +37,7 @@ sub get_standard_option { my ($name, $base) = @_; my $std = $standard_options->{$name}; - die "no such standard option\n" if !$std; + die "no such standard option '$name'\n" if !$std; my $res = $base || {}; @@ -266,6 +266,48 @@ register_standard_option('remote-viewer-config', { }, }); +register_format('pve-startup-order', \&pve_verify_startup_order); +sub pve_verify_startup_order { + my ($value, $noerr) = @_; + + return $value if pve_parse_startup_order($value); + + return undef if $noerr; + + die "unable to parse startup options\n"; +} + +sub pve_parse_startup_order { + my ($value) = @_; + + return undef if !$value; + + my $res = {}; + + foreach my $p (split(/,/, $value)) { + next if $p =~ m/^\s*$/; + + if ($p =~ m/^(order=)?(\d+)$/) { + $res->{order} = $2; + } elsif ($p =~ m/^up=(\d+)$/) { + $res->{up} = $1; + } elsif ($p =~ m/^down=(\d+)$/) { + $res->{down} = $1; + } else { + return undef; + } + } + + return $res; +} + +PVE::JSONSchema::register_standard_option('pve-startup-order', { + description => "Startup and shutdown behavior. Order is a non-negative number defining the general startup order. Shutdown in done with reverse ordering. Additionally you can set the 'up' or 'down' delay in seconds, which specifies a delay to wait before the next VM is started or stopped.", + optional => 1, + type => 'string', format => 'pve-startup-order', + typetext => '[[order=]\d+] [,up=\d+] [,down=\d+] ', +}); + sub check_format { my ($format, $value) = @_;