]>
git.proxmox.com Git - pve-firewall.git/blob - src/PVE/API2/Firewall/Groups.pm
0a6126afa0105642eb937e6c21f2aeec733872b9
1 package PVE
::API2
::Firewall
::Groups
;
5 use PVE
::JSONSchema
qw(get_standard_option);
8 use PVE
::API2
::Firewall
::Rules
;
10 use Data
::Dumper
; # fixme: remove
12 use base
qw(PVE::RESTHandler);
14 __PACKAGE__-
>register_method({
15 name
=> 'list_security_groups',
18 description
=> "List security groups.",
20 additionalProperties
=> 0,
27 name
=> get_standard_option
('pve-security-group-name'),
30 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
35 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
38 foreach my $group (keys %{$cluster_conf->{groups
}}) {
39 push @$res, { name
=> $group, count
=> scalar(@{$cluster_conf->{groups
}->{$group}}) };
45 __PACKAGE__-
>register_method({
46 name
=> 'create_security_group',
49 description
=> "Create new security group.",
52 additionalProperties
=> 0,
54 name
=> get_standard_option
('pve-security-group-name'),
55 rename => get_standard_option
('pve-security-group-name', {
56 description
=> "Rename an existing security group.",
61 returns
=> { type
=> 'null' },
65 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
67 foreach my $name (keys %{$cluster_conf->{groups
}}) {
68 raise_param_exc
({ name
=> "Security group '$name' already exists" })
69 if $name eq $param->{name
};
72 if ($param->{rename}) {
73 raise_param_exc
({ name
=> "Security group '$param->{rename}' does not exists" })
74 if !$cluster_conf->{groups
}->{$param->{rename}};
75 my $data = delete $cluster_conf->{groups
}->{$param->{rename}};
76 $cluster_conf->{groups
}->{$param->{name
}} = $data;
78 $cluster_conf->{groups
}->{$param->{name
}} = [];
81 PVE
::Firewall
::save_clusterfw_conf
($cluster_conf);
87 __PACKAGE__-
>register_method({
88 name
=> 'delete_security_group',
91 description
=> "Delete security group.",
94 additionalProperties
=> 0,
96 name
=> get_standard_option
('pve-security-group-name'),
99 returns
=> { type
=> 'null' },
103 my $cluster_conf = PVE
::Firewall
::load_clusterfw_conf
();
105 return undef if !$cluster_conf->{groups
}->{$param->{name
}};
107 die "Security group '$param->{name}' is not empty\n"
108 if scalar(@{$cluster_conf->{groups
}->{$param->{name
}}});
110 delete $cluster_conf->{groups
}->{$param->{name
}};
112 PVE
::Firewall
::save_clusterfw_conf
($cluster_conf);
117 __PACKAGE__-
>register_method ({
118 subclass
=> "PVE::API2::Firewall::GroupRules",