]> git.proxmox.com Git - pve-firewall.git/commitdiff
implement option API for cluster.fw
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 1 Apr 2014 09:20:47 +0000 (11:20 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 1 Apr 2014 09:20:47 +0000 (11:20 +0200)
src/PVE/API2/Firewall/Cluster.pm

index 2296baac7d36d06d253a1d08172e72b11a5214de..ce56a6d65cea908d75b7a2d315e534bdb1d75636 100644 (file)
@@ -2,11 +2,14 @@ package PVE::API2::Firewall::Cluster;
 
 use strict;
 use warnings;
 
 use strict;
 use warnings;
+use PVE::Exception qw(raise raise_param_exc raise_perm_exc);
 use PVE::JSONSchema qw(get_standard_option);
 
 use PVE::Firewall;
 use PVE::API2::Firewall::Groups;
 
 use PVE::JSONSchema qw(get_standard_option);
 
 use PVE::Firewall;
 use PVE::API2::Firewall::Groups;
 
+#fixme: locking?
+
 use Data::Dumper; # fixme: remove
 
 use base qw(PVE::RESTHandler);
 use Data::Dumper; # fixme: remove
 
 use base qw(PVE::RESTHandler);
@@ -45,3 +48,87 @@ __PACKAGE__->register_method({
 
        return $result;
     }});
 
        return $result;
     }});
+
+__PACKAGE__->register_method({
+    name => 'get_options',
+    path => 'options',
+    method => 'GET',
+    description => "Get Firewall options.",
+    parameters => {
+       additionalProperties => 0,
+    },
+    returns => {
+       type => "object",
+       #additionalProperties => 1,
+       properties => {
+           enable => {
+               type => 'boolean',
+               optional => 1,
+           },
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $cluster_conf = PVE::Firewall::load_clusterfw_conf();
+
+       my $options = $cluster_conf->{options};
+
+       return $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',
+    path => 'options',
+    method => 'PUT',
+    description => "Set Firewall options.",
+    parameters => {
+       additionalProperties => 0,
+       properties => &$add_option_properties({
+           delete => {
+               type => 'string', format => 'pve-configid-list',
+               description => "A list of settings you want to delete.",
+               optional => 1,
+           },
+       }),
+    },
+    returns => { type => "null" },
+    code => sub {
+       my ($param) = @_;
+
+       my $cluster_conf = PVE::Firewall::load_clusterfw_conf();
+
+       if ($param->{delete}) {
+           foreach my $opt (PVE::Tools::split_list($param->{delete})) {
+               raise_param_exc({ delete => "no such option '$opt'" }) 
+                   if !$option_properties->{$opt};
+               delete $cluster_conf->{options}->{$opt};
+           }
+       }
+
+       if (defined($param->{enable})) {
+           $cluster_conf->{options}->{enable} = $param->{enable} ? 1 : 0;
+       }
+
+
+       PVE::Firewall::save_clusterfw_conf($cluster_conf);
+
+       return undef;
+    }});