From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id ADB2D8D75 for ; Wed, 16 Nov 2022 18:09:53 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 913D8231F2 for ; Wed, 16 Nov 2022 18:09:23 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 16 Nov 2022 18:09:22 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id F2BB94497F; Wed, 16 Nov 2022 18:09:21 +0100 (CET) Message-ID: <11b07c1d-d208-3d23-8b50-d3d4d9dd21f7@proxmox.com> Date: Wed, 16 Nov 2022 18:09:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101 Thunderbird/107.0 Content-Language: en-GB To: Proxmox VE development discussion , Alexandre Derumier References: <20220629090833.456340-1-aderumier@odiso.com> <20220629090833.456340-3-aderumier@odiso.com> From: Thomas Lamprecht In-Reply-To: <20220629090833.456340-3-aderumier@odiso.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: =?UTF-8?Q?0=0A=09?=AWL -0.031 Adjusted score from AWL reputation of From: =?UTF-8?Q?address=0A=09?=BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict =?UTF-8?Q?Alignment=0A=09?=SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF =?UTF-8?Q?Record=0A=09?=SPF_PASS -0.001 SPF: sender matches SPF =?UTF-8?Q?record=0A=09?=URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [firewall.pm, helpers.pm, followup.re] Subject: [pve-devel] applied: [PATCH pve-firewall 1/1] move clone_vmfw_conf && remove_vmfw_conf to a Helpers X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Nov 2022 17:09:53 -0000 applied, but had to do some follow ups (see below) Am 29/06/2022 um 11:08 schrieb Alexandre Derumier: > Signed-off-by: Alexandre Derumier > --- > src/PVE/Firewall.pm | 25 ---------------------- > src/PVE/Firewall/Helpers.pm | 41 +++++++++++++++++++++++++++++++++++++ > src/PVE/Firewall/Makefile | 12 +++++++++++ > src/PVE/Makefile | 2 ++ > 4 files changed, 55 insertions(+), 25 deletions(-) > create mode 100644 src/PVE/Firewall/Helpers.pm > create mode 100644 src/PVE/Firewall/Makefile > > diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm > index 71746d2..e6cf4cd 100644 > --- a/src/PVE/Firewall.pm > +++ b/src/PVE/Firewall.pm > @@ -3340,31 +3340,6 @@ sub save_vmfw_conf { > } > } > > -sub remove_vmfw_conf { > - my ($vmid) = @_; > - > - my $vmfw_conffile = "$pvefw_conf_dir/$vmid.fw"; > - > - unlink $vmfw_conffile; > -} > - > -sub clone_vmfw_conf { > - my ($vmid, $newid) = @_; > - > - my $sourcevm_conffile = "$pvefw_conf_dir/$vmid.fw"; > - my $clonevm_conffile = "$pvefw_conf_dir/$newid.fw"; > - > - lock_vmfw_conf($newid, 10, sub { > - if (-f $clonevm_conffile) { > - unlink $clonevm_conffile; > - } > - if (-f $sourcevm_conffile) { > - my $data = PVE::Tools::file_get_contents($sourcevm_conffile); > - PVE::Tools::file_set_contents($clonevm_conffile, $data); > - } > - }); > -} keeping above as skeleton allows to avoid a breakage on older qemu-server/pve-container so I did that in a followup.re > - > sub read_vm_firewall_configs { > my ($cluster_conf, $vmdata, $dir) = @_; > > diff --git a/src/PVE/Firewall/Helpers.pm b/src/PVE/Firewall/Helpers.pm > new file mode 100644 > index 0000000..3112ebc > --- /dev/null > +++ b/src/PVE/Firewall/Helpers.pm > @@ -0,0 +1,41 @@ > +package PVE::Firewall::Helpers; > + > +use strict; > +use warnings; > + > +use PVE::Tools qw(file_get_contents file_set_contents); > + > +use base 'Exporter'; > +our @EXPORT_OK = qw( > +remove_vmfw_conf > +clone_vmfw_conf > +); > + > +my $pvefw_conf_dir = "/etc/pve/firewall"; > + > +sub remove_vmfw_conf { > + my ($vmid) = @_; > + > + my $vmfw_conffile = "$pvefw_conf_dir/$vmid.fw"; > + > + unlink $vmfw_conffile; > +} > + > +sub clone_vmfw_conf { > + my ($vmid, $newid) = @_; > + > + my $sourcevm_conffile = "$pvefw_conf_dir/$vmid.fw"; > + my $clonevm_conffile = "$pvefw_conf_dir/$newid.fw"; > + > + lock_vmfw_conf($newid, 10, sub { this was not in scope here so it only worked by luck, if at all? As it only depends on PVE::Cluster, which is probably in the use paths in most more involved/API facing modules anyway, I moved it over in a follow up.