]> git.proxmox.com Git - pve-firewall.git/commitdiff
implement API for cluster.fw policy_in and policy_out options
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 14 Apr 2014 10:51:16 +0000 (12:51 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 14 Apr 2014 10:51:16 +0000 (12:51 +0200)
src/PVE/API2/Firewall/Cluster.pm

index 8d575da5e85985d2b75cca6d86629dd91c520752..d104c34d92c9b3c2824904bb55facf19670517d3 100644 (file)
@@ -62,6 +62,36 @@ __PACKAGE__->register_method({
        return $result;
     }});
 
+my $option_properties = {
+    enable => {
+       type => 'boolean',
+       optional => 1,
+    },
+    policy_in => {
+       description => "Input policy.",
+       type => 'string',
+       optional => 1,
+       enum => ['ACCEPT', 'REJECT', 'DROP'],
+    },
+    policy_out => { 
+       description => "Output policy.",
+       type => 'string',
+       optional => 1,
+       enum => ['ACCEPT', 'REJECT', 'DROP'],
+    },
+};
+
+my $add_option_properties = sub {
+    my ($properties) = @_;
+
+    foreach my $k (keys %$option_properties) {
+       $properties->{$k} = $option_properties->{$k};
+    }
+    
+    return $properties;
+};
+
+
 __PACKAGE__->register_method({
     name => 'get_options',
     path => 'options',
@@ -73,12 +103,7 @@ __PACKAGE__->register_method({
     returns => {
        type => "object",
        #additionalProperties => 1,
-       properties => {
-           enable => {
-               type => 'boolean',
-               optional => 1,
-           },
-       },
+       properties => $option_properties,
     },
     code => sub {
        my ($param) = @_;
@@ -88,22 +113,6 @@ __PACKAGE__->register_method({
        return PVE::Firewall::copy_opject_with_digest($cluster_conf->{options});
     }});
 
-my $option_properties = {
-    enable => {
-       type => 'boolean',
-       optional => 1,
-    },
-};
-
-my $add_option_properties = sub {
-    my ($properties) = @_;
-
-    foreach my $k (keys %$option_properties) {
-       $properties->{$k} = $option_properties->{$k};
-    }
-    
-    return $properties;
-};
 
 __PACKAGE__->register_method({
     name => 'set_options',
@@ -140,7 +149,12 @@ __PACKAGE__->register_method({
        }
 
        if (defined($param->{enable})) {
-           $cluster_conf->{options}->{enable} = $param->{enable} ? 1 : 0;
+           $param->{enable} = $param->{enable} ? 1 : 0;
+       }
+
+       foreach my $k (keys %$option_properties) {
+           next if !defined($param->{$k});
+           $cluster_conf->{options}->{$k} = $param->{$k}; 
        }
 
        PVE::Firewall::save_clusterfw_conf($cluster_conf);