implement delete parameter for rule update API
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 3 Apr 2014 11:28:50 +0000 (13:28 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 3 Apr 2014 11:28:50 +0000 (13:28 +0200)
src/PVE/API2/Firewall/Rules.pm
src/PVE/Firewall.pm

index 9db899d..032631d 100644 (file)
@@ -185,6 +185,12 @@ sub register_update_rule {
        optional => 1,
     };
 
+    $properties->{delete} = {
+       type => 'string', format => 'pve-configid-list',
+       description => "A list of settings you want to delete.",
+       optional => 1,
+    };
+
     my $update_rule_properties = PVE::Firewall::add_rule_properties($properties);
 
     $class->register_method({
@@ -229,6 +235,8 @@ sub register_update_rule {
                    if !defined($param->{action});
 
                PVE::Firewall::copy_rule_data($rule, $param);
+               
+               PVE::Firewall::delete_rule_properties($rule, $param->{'delete'}) if $param->{'delete'};
            }
 
            $class->save_rules($param, $fw_conf, $rules);
index 8fd0f48..6d4127e 100644 (file)
@@ -775,6 +775,20 @@ sub add_rule_properties {
     return $properties;
 }
 
+sub delete_rule_properties {
+    my ($rule, $delete_str) = @_;
+    
+    foreach my $opt (PVE::Tools::split_list($delete_str)) {
+       raise_param_exc({ 'delete' => "no such property ('$opt')"})
+           if !defined($rule_properties->{$opt});
+       raise_param_exc({ 'delete' => "unable to delete required property '$opt'"})
+           if $opt eq 'type' || $opt eq 'action';
+       delete $rule->{$opt};
+    }
+
+    return $rule;
+}
+
 sub copy_rule_data {
     my ($rule, $param) = @_;