From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api] pmgdb: dump: replace active flag with rules enum
Date: Tue, 27 Feb 2024 15:22:03 +0100 [thread overview]
Message-ID: <20240227142203.233611-1-s.ivanov@proxmox.com> (raw)
this addresses the odd/unintuitive behavior of `pmgdb dump --active 0`
which currently prints all rules, why printing only the inactive ones
might be expected.
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
tested by running all 4 variants (active, inactive, all, no rule argument)
and diffing the resulting output)
src/PMG/CLI/pmgdb.pm | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/PMG/CLI/pmgdb.pm b/src/PMG/CLI/pmgdb.pm
index 0ac3f82..cc9d000 100644
--- a/src/PMG/CLI/pmgdb.pm
+++ b/src/PMG/CLI/pmgdb.pm
@@ -39,11 +39,13 @@ sub print_objects {
}
sub print_rule {
- my ($ruledb, $rule, $active_only) = @_;
+ my ($ruledb, $rule, $rule_status) = @_;
$ruledb->load_rule_attributes($rule);
- return if !$rule->{active} && $active_only;
+ return if !$rule->{active} && $rule_status eq 'active';
+ return if $rule->{active} && $rule_status eq 'inactive';
+
my $direction = {
0 => 'in',
1 => 'out',
@@ -114,11 +116,12 @@ __PACKAGE__->register_method ({
parameters => {
additionalProperties => 0,
properties => {
- active => {
- type => 'boolean',
- description => "Print only active rules",
+ rules => {
+ description => "Which rules should be printed",
+ type => 'string',
+ enum => [qw(all active inactive)],
+ default => 'all',
optional => 1,
- default => 0,
},
},
},
@@ -126,13 +129,14 @@ __PACKAGE__->register_method ({
code => sub {
my ($param) = @_;
+ my $rule_status = $param->{rules} // '';
my $dbh = PMG::DBTools::open_ruledb("Proxmox_ruledb");
my $ruledb = PMG::RuleDB->new($dbh);
my $rules = $ruledb->load_rules();
foreach my $rule (@$rules) {
- print_rule($ruledb, $rule, $param->{active});
+ print_rule($ruledb, $rule, $rule_status);
}
$ruledb->close();
--
2.39.2
next reply other threads:[~2024-02-27 14:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 14:22 Stoiko Ivanov [this message]
2024-02-27 16:01 ` [pmg-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240227142203.233611-1-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox