From: Dietmar Maurer Date: Tue, 1 Apr 2014 09:20:47 +0000 (+0200) Subject: implement option API for cluster.fw X-Git-Url: https://git.proxmox.com/?p=pve-firewall.git;a=commitdiff_plain;h=1df4ba7e4d9a31cea72c056b4242e0a810248894;hp=b4366f0078a37b8542dbeca999dc39cbd4a00f7f implement option API for cluster.fw --- diff --git a/src/PVE/API2/Firewall/Cluster.pm b/src/PVE/API2/Firewall/Cluster.pm index 2296baa..ce56a6d 100644 --- a/src/PVE/API2/Firewall/Cluster.pm +++ b/src/PVE/API2/Firewall/Cluster.pm @@ -2,11 +2,14 @@ package PVE::API2::Firewall::Cluster; 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; +#fixme: locking? + use Data::Dumper; # fixme: remove use base qw(PVE::RESTHandler); @@ -45,3 +48,87 @@ __PACKAGE__->register_method({ 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; + }});