[pve-devel] [PATCH pve-container 2/2] Replace parsing code for -net* and -mp*

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Sep 22 13:48:52 CEST 2015


Use the new JSONSchema provided parser which also verifies
the parameters with their schemas.
---
 src/PVE/LXC.pm | 33 +++++++++------------------------
 1 file changed, 9 insertions(+), 24 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index f5b3a5b..7a6803e 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -862,28 +862,15 @@ sub parse_ct_mountpoint {
 
     $data //= '';
 
-    my $res = {};
-
-    foreach my $p (split (/,/, $data)) {
-	next if $p =~ m/^\s*$/;
-
-	if ($p =~ m/^(volume|backup|size|mp)=(.+)$/) {
-	    my ($k, $v) = ($1, $2);
-	    return undef if defined($res->{$k});
-	    $res->{$k} = $v;
-	} else {
-	    if (!$res->{volume} && $p !~ m/=/) {
-		$res->{volume} = $p;
-	    } else {
-		return undef;
-	    }
-	}
+    my $res;
+    eval { $res = PVE::JSONSchema::parse_property_string($mp_desc, $data) };
+    if ($@) {
+	warn $@;
+	return undef;
     }
 
     return undef if !defined($res->{volume});
 
-    return undef if $res->{backup} && $res->{backup} !~ m/^(yes|no)$/;
-
     if ($res->{size}) {
 	return undef if !defined($res->{size} = &$parse_size($res->{size}));
     }
@@ -933,12 +920,10 @@ sub parse_lxc_network {
 
     return $res if !$data;
 
-    foreach my $pv (split (/,/, $data)) {
-	if ($pv =~ m/^(bridge|hwaddr|mtu|name|ip|ip6|gw|gw6|firewall|tag)=(\S+)$/) {
-	    $res->{$1} = $2;
-	} else {
-	    return undef;
-	}
+    eval { $res = PVE::JSONSchema::parse_property_string($netconf_desc, $data) };
+    if ($@) {
+	warn $@;
+	return undef;
     }
 
     $res->{type} = 'veth';
-- 
2.1.4





More information about the pve-devel mailing list