]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/SectionConfig.pm
SectionConfig::check_value: return bool/numbers as numeric value
[pve-common.git] / src / PVE / SectionConfig.pm
index a6301e262598d0ee7886144ec104cb51301e5b24..b1e96a4ed42bd9625e0a53b1ec932d061ea1f053 100644 (file)
@@ -51,7 +51,7 @@ sub plugindata {
 }   
 
 sub createSchema {
-    my ($class) = @_;
+    my ($class, $skip_type) = @_;
 
     my $pdata = $class->private();
     my $propertyList = $pdata->{propertyList};
@@ -71,6 +71,8 @@ sub createSchema {
     };
 
     foreach my $p (keys %$propertyList) {
+       next if $skip_type && $p eq 'type';
+
        if (!$propertyList->{$p}->{optional}) {
            $props->{$p} = $propertyList->{$p};
            next;
@@ -104,7 +106,7 @@ sub createSchema {
 }
 
 sub updateSchema {
-    my ($class) = @_;
+    my ($class, $single_class) = @_;
 
     my $pdata = $class->private();
     my $propertyList = $pdata->{propertyList};
@@ -112,8 +114,15 @@ sub updateSchema {
 
     my $props = {};
 
+    my $filter_type = $class->type() if $single_class;
+
     foreach my $p (keys %$propertyList) {
        next if $p eq 'type';
+
+       my $copts = $class->options();
+
+       next if defined($filter_type) && !defined($copts->{$p});
+
        if (!$propertyList->{$p}->{optional}) {
            $props->{$p} = $propertyList->{$p};
            next;
@@ -121,7 +130,6 @@ sub updateSchema {
 
        my $modifyable = 0;
 
-       my $copts = $class->options();
        $modifyable = 1 if defined($copts->{$p}) && !$copts->{$p}->{fixed};
 
        foreach my $t (keys %$plugins) {
@@ -251,6 +259,10 @@ sub check_value {
        }
     }
 
+    if ($ct eq 'boolean' || $ct eq 'integer' || $ct eq 'number') {
+       return $value + 0; # convert to number
+    }
+
     return $value;
 }
 
@@ -447,7 +459,8 @@ sub write_config {
 
        my $done_hash = { comment => 1, disable => 1};
 
-       foreach my $k (keys %$opts) {
+       my @option_keys = sort keys %$opts;
+       foreach my $k (@option_keys) {
            next if $opts->{$k}->{optional};
            $done_hash->{$k} = 1;
            my $v = $scfg->{$k};
@@ -457,7 +470,7 @@ sub write_config {
            $data .= &$format_config_line($propertyList->{$k}, $k, $v);
        }
 
-       foreach my $k (keys %$opts) {
+       foreach my $k (@option_keys) {
            next if defined($done_hash->{$k});
            my $v = $scfg->{$k};
            next if !defined($v);