]> git.proxmox.com Git - pve-container.git/commitdiff
Replace parsing code for -net* and -mp*
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 22 Sep 2015 11:48:52 +0000 (13:48 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 23 Sep 2015 06:27:24 +0000 (08:27 +0200)
Use the new JSONSchema provided parser which also verifies
the parameters with their schemas.

src/PVE/LXC.pm

index 29e55d08bbd4210a95f6e4a705e4e74aecd2c1eb..686e55e10c067c9a61271628183f430666bc1f54 100644 (file)
@@ -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';