[pmg-devel] [PATCH pmg-api 3/3] pmgdb: add active parameter to dump

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Feb 26 20:11:28 CET 2024


Am 22/02/2024 um 22:06 schrieb Stoiko Ivanov:
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
>  src/PMG/CLI/pmgdb.pm | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/src/PMG/CLI/pmgdb.pm b/src/PMG/CLI/pmgdb.pm
> index 28e9583..0ac3f82 100644
> --- a/src/PMG/CLI/pmgdb.pm
> +++ b/src/PMG/CLI/pmgdb.pm
> @@ -39,10 +39,11 @@ sub print_objects {
>  }
>  
>  sub print_rule {
> -    my ($ruledb, $rule) = @_;
> +    my ($ruledb, $rule, $active_only) = @_;
>  
>      $ruledb->load_rule_attributes($rule);
>  
> +    return if !$rule->{active} && $active_only;
>      my $direction = {
>  	0 => 'in',
>  	1 => 'out',
> @@ -112,7 +113,14 @@ __PACKAGE__->register_method ({
>      description => "Print the PMG rule database.",
>      parameters => {
>  	additionalProperties => 0,
> -	properties => {},
> +	properties => {
> +	    active => {
> +		type => 'boolean',
> +		description => "Print only active rules",
> +		optional => 1,
> +		default => 0,
> +	    },
> +	},
>      },
>      returns => { type => 'null'},
>      code => sub {
> @@ -124,7 +132,7 @@ __PACKAGE__->register_method ({
>  	my $rules = $ruledb->load_rules();
>  
>  	foreach my $rule (@$rules) {
> -	    print_rule($ruledb, $rule);
> +	    print_rule($ruledb, $rule, $param->{active});
>  	}
>  
>  	$ruledb->close();


If I call this with active set to disabled, i.e. as `pmgdb dump --active 0`, then
I still get the active rules, which feels rather a bit wrong.

IMO this could be interpreted as ternary:

1. undef (not passed) -> both
2. true (--active[=1]) -> active only
3. false (--active=0) -> incative only




More information about the pmg-devel mailing list