my $properties = $class->additional_parameters();
my $create_rule_properties = PVE::Firewall::add_rule_properties($properties);
-
+ $create_rule_properties->{action}->{optional} = 0;
+ $create_rule_properties->{type}->{optional} = 0;
+
$class->register_method({
name => 'create_rule',
path => '',
my ($fw_conf, $rules) = $class->load_config($param);
my $digest = $fw_conf->{digest};
-
- my $rule = { type => 'out', action => 'ACCEPT', enable => 0};
+
+ my $rule = {};
PVE::Firewall::copy_rule_data($rule, $param);
+ $rule->{enable} = 0 if !defined($param->{enable});
+
unshift @$rules, $rule;
$class->save_rules($param, $fw_conf, $rules);
push @$newrules, $rule if $moveto >= scalar(@$rules);
$rules = $newrules;
} else {
+ raise_param_exc({ type => "property is missing"})
+ if !defined($param->{type});
+ raise_param_exc({ action => "property is missing"})
+ if !defined($param->{action});
+
PVE::Firewall::copy_rule_data($rule, $param);
}
__PACKAGE__->register_handlers();
+package PVE::API2::Firewall::VMRules;
+
+use strict;
+use warnings;
+use PVE::JSONSchema qw(get_standard_option);
+
+use base qw(PVE::API2::Firewall::RulesBase);
+
+__PACKAGE__->additional_parameters({
+ node => get_standard_option('pve-node'),
+ vmid => get_standard_option('pve-vmid'),
+});
+
+sub load_config {
+ my ($class, $param) = @_;
+
+ my $fw_conf = PVE::Firewall::load_vmfw_conf($param->{vmid});
+ my $rules = $fw_conf->{rules};
+
+ return ($fw_conf, $rules);
+}
+
+sub save_rules {
+ my ($class, $param, $fw_conf, $rules) = @_;
+
+ $fw_conf->{rules} = $rules;
+ PVE::Firewall::save_vmfw_conf($param->{vmid}, $fw_conf);
+}
+
+__PACKAGE__->register_handlers();
+
1;