[pve-devel] [PATCH v2 container 1/2] qemu-server: add support for multiple IP addresses

Julian Pawlowski julian at pawlowski.me
Wed Oct 24 08:57:22 CEST 2018


Signed-off-by: Julian Pawlowski <julian at pawlowski.me>
---
 src/PVE/JSONSchema.pm | 97 ++++++++++++++++++++++++++-----------------
 1 file changed, 60 insertions(+), 37 deletions(-)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index fb58ad3..dbc8507 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -601,43 +601,66 @@ sub parse_property_string {
     my $default_key;
 
     my $res = {};
-    foreach my $part (split(/,/, $data)) {
-	next if $part =~ /^\s*$/;
-
-	if ($part =~ /^([^=]+)=(.+)$/) {
-	    my ($k, $v) = ($1, $2);
-	    die "duplicate key in comma-separated list property: $k\n" if defined($res->{$k});
-	    my $schema = $format->{$k};
-	    if (my $alias = $schema->{alias}) {
-		if (my $key_alias = $schema->{keyAlias}) {
-		    die "key alias '$key_alias' is already defined\n" if defined($res->{$key_alias});
-		    $res->{$key_alias} = $k;
-		}
-		$k = $alias;
-		$schema = $format->{$k};
-	    }
-
-	    die "invalid key in comma-separated list property: $k\n" if !$schema;
-	    if ($schema->{type} && $schema->{type} eq 'boolean') {
-		$v = parse_boolean($v) // $v;
-	    }
-	    $res->{$k} = $v;
-	} elsif ($part !~ /=/) {
-	    die "duplicate key in comma-separated list property: $default_key\n" if $default_key;
-	    foreach my $key (keys %$format) {
-		if ($format->{$key}->{default_key}) {
-		    $default_key = $key;
-		    if (!$res->{$default_key}) {
-			$res->{$default_key} = $part;
-			last;
-		    }
-		    die "duplicate key in comma-separated list property: $default_key\n";
-		}
-	    }
-	    die "value without key, but schema does not define a default key\n" if !$default_key;
-	} else {
-	    die "missing key in comma-separated list property\n";
-	}
+    foreach my $part ( split( /,/, $data ) ) {
+        next if $part =~ /^\s*$/;
+
+        if ( $part =~ /^([^=]+)=(.+)$/ ) {
+            my ( $k, $v ) = ( $1, $2 );
+            my $schema = $format->{$k};
+
+            die "invalid key in comma-separated list property: $k\n"
+              if !$schema;
+
+            if ( my $alias = $schema->{alias} ) {
+                if ( my $key_alias = $schema->{keyAlias} ) {
+                    die "key alias '$key_alias' is already defined\n"
+                      if defined( $res->{$key_alias} );
+                    $res->{$key_alias} = $k;
+                }
+                $k      = $alias;
+                $schema = $format->{$k};
+            }
+
+            die "duplicate key in comma-separated list property: $k\n"
+              if defined( $res->{$k} && !$schema->{multiple} );
+
+            die "standalone-only key in comma-separated property list: $k\n"
+              if ( defined( $res->{$k} )
+                && ref( $res->{$k} ) eq "ARRAY"
+                && ( $default_key || grep ( /$default_key/, @{ $res->{$k} } ) )
+              );
+
+            if ( $schema->{type} && $schema->{type} eq 'boolean' ) {
+                $v = parse_boolean($v) // $v;
+            }
+
+            if ( $schema->{multiple} ) {
+                push @{ $res->{$k} }, $v;
+            }
+            else {
+                $res->{$k} = $v;
+            }
+        }
+        elsif ( $part !~ /=/ ) {
+            die "duplicate key in comma-separated list property: $default_key\n"
+              if $default_key;
+            foreach my $key ( keys %$format ) {
+                if ( $format->{$key}->{default_key} ) {
+                    $default_key = $key;
+                    if ( !$res->{$default_key} ) {
+                        $res->{$default_key} = $part;
+                        last;
+                    }
+                    die
+"duplicate key in comma-separated list property: $default_key\n";
+                }
+            }
+            die "value without key, but schema does not define a default key\n"
+              if !$default_key;
+        }
+        else {
+            die "missing key in comma-separated list property\n";
+        }
     }
 
     my $errors = {};
-- 
2.19.1




More information about the pve-devel mailing list