]> git.proxmox.com Git - pve-firewall.git/blame - src/PVE/Firewall/Helpers.pm
move clone_vmfw_conf && remove_vmfw_conf to a Helpers
[pve-firewall.git] / src / PVE / Firewall / Helpers.pm
CommitLineData
5bdc31fb
AD
1package PVE::Firewall::Helpers;
2
3use strict;
4use warnings;
5
6use PVE::Tools qw(file_get_contents file_set_contents);
7
8use base 'Exporter';
9our @EXPORT_OK = qw(
10remove_vmfw_conf
11clone_vmfw_conf
12);
13
14my $pvefw_conf_dir = "/etc/pve/firewall";
15
16sub remove_vmfw_conf {
17 my ($vmid) = @_;
18
19 my $vmfw_conffile = "$pvefw_conf_dir/$vmid.fw";
20
21 unlink $vmfw_conffile;
22}
23
24sub clone_vmfw_conf {
25 my ($vmid, $newid) = @_;
26
27 my $sourcevm_conffile = "$pvefw_conf_dir/$vmid.fw";
28 my $clonevm_conffile = "$pvefw_conf_dir/$newid.fw";
29
30 lock_vmfw_conf($newid, 10, sub {
31 if (-f $clonevm_conffile) {
32 unlink $clonevm_conffile;
33 }
34 if (-f $sourcevm_conffile) {
35 my $data = file_get_contents($sourcevm_conffile);
36 file_set_contents($clonevm_conffile, $data);
37 }
38 });
39}
40
411;