From 271f287bdf4294398a67323857f904d649bfa90b Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 14 Apr 2014 12:51:16 +0200 Subject: [PATCH] implement API for cluster.fw policy_in and policy_out options --- src/PVE/API2/Firewall/Cluster.pm | 60 ++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/PVE/API2/Firewall/Cluster.pm b/src/PVE/API2/Firewall/Cluster.pm index 8d575da..d104c34 100644 --- a/src/PVE/API2/Firewall/Cluster.pm +++ b/src/PVE/API2/Firewall/Cluster.pm @@ -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); -- 2.39.2