[pmg-devel] [PATCH WIP api 08/11] match groups: add API endpoints for create/delete

Leo Nunner l.nunner at proxmox.com
Thu Sep 14 11:52:29 CEST 2023


Add API endpoints to create and delete match groups associated with a
given rule.

Signed-off-by: Leo Nunner <l.nunner at proxmox.com>
---
 src/PMG/API2/Rules.pm | 79 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/src/PMG/API2/Rules.pm b/src/PMG/API2/Rules.pm
index ad3f6c7..a048872 100644
--- a/src/PMG/API2/Rules.pm
+++ b/src/PMG/API2/Rules.pm
@@ -201,6 +201,85 @@ __PACKAGE__->register_method ({
 	return undef;
    }});
 
+__PACKAGE__->register_method ({
+	name => "create_matchgroup",
+	path => "matchgroup",
+	method => 'POST',
+	description => "Create a new match group for the specified object group.",
+	proxyto => 'master',
+	protected => 1,
+	permissions => { check => [ 'admin' ] },
+	parameters => {
+	    additionalProperties => 0,
+	    properties => {
+		id => {
+		    description => "Rule ID.",
+		    type => 'integer',
+		},
+		class => {
+		    description => "Match group type.",
+		    type => 'string',
+		},
+		name => {
+		    description => "Match group name.",
+		    type => 'string',
+		},
+	    },
+	},
+	returns => {
+	    description=>  "Match group ID.",
+	    type => 'integer',
+	},
+	code => sub {
+	    my ($param) = @_;
+
+	    my $rdb = PMG::RuleDB->new();
+
+	    my $id = $param->{id};
+	    my $class = $param->{class};
+	    my $name = $param->{name};
+
+	    return $rdb->rule_add_match_group($id, $class, $name);
+	}});
+
+__PACKAGE__->register_method ({
+	name => "delete_matchgroup",
+	path => "matchgroup",
+	method => 'DELETE',
+	description => "Delete a match group.",
+	proxyto => 'master',
+	protected => 1,
+	permissions => { check => [ 'admin' ] },
+	parameters => {
+	    additionalProperties => 0,
+	    properties => {
+		id => {
+		    description => "Rule ID.",
+		    type => 'integer',
+		},
+		group => {
+		    description => "Match group ID.",
+		    type => 'integer',
+		},
+	    },
+	},
+	returns => {
+	    type => 'null',
+	},
+	code => sub {
+	    my ($param) = @_;
+
+	    my $rdb = PMG::RuleDB->new();
+
+	    my $id = $param->{id};
+	    my $group = $param->{group};
+
+	    $rdb->rule_remove_match_group($id, $group);
+
+	    return;
+	}});
+
+
 my $register_rule_group_api = sub {
     my ($name) = @_;
 
-- 
2.39.2





More information about the pmg-devel mailing list