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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E628E7E55F for ; Wed, 10 Nov 2021 15:02:58 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E28E71D800 for ; Wed, 10 Nov 2021 15:02:58 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 87BB21D7DA for ; Wed, 10 Nov 2021 15:02:57 +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 538E544B57 for ; Wed, 10 Nov 2021 15:02:57 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Wed, 10 Nov 2021 15:02:53 +0100 Message-Id: <20211110140256.1863209-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211110140256.1863209-1-d.csapak@proxmox.com> References: <20211110140256.1863209-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.227 Adjusted score from AWL reputation of From: address 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 Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [plugin.pm, vzdump.pm] Subject: [pve-devel] [PATCH manager 1/4] Jobs/VZDump: encode/decode 'prune-backups' where needed 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, 10 Nov 2021 14:02:59 -0000 we want to write it out to the config as propertyString, but want it as object in the api (for compatiblity) Signed-off-by: Dominik Csapak --- PVE/Jobs/Plugin.pm | 15 +++++++++++++++ PVE/Jobs/VZDump.pm | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/PVE/Jobs/Plugin.pm b/PVE/Jobs/Plugin.pm index 69c31cf2..9cf7f98d 100644 --- a/PVE/Jobs/Plugin.pm +++ b/PVE/Jobs/Plugin.pm @@ -52,6 +52,21 @@ sub parse_config { return $cfg; } +# call the plugin specific decode/encode code +sub decode_value { + my ($class, $type, $key, $value) = @_; + + my $plugin = __PACKAGE__->lookup($type); + return $plugin->decode_value($type, $key, $value); +} + +sub encode_value { + my ($class, $type, $key, $value) = @_; + + my $plugin = __PACKAGE__->lookup($type); + return $plugin->encode_value($type, $key, $value); +} + sub run { my ($class, $cfg) = @_; # implement in subclass diff --git a/PVE/Jobs/VZDump.pm b/PVE/Jobs/VZDump.pm index 043b7ace..87733e74 100644 --- a/PVE/Jobs/VZDump.pm +++ b/PVE/Jobs/VZDump.pm @@ -7,6 +7,7 @@ use PVE::INotify; use PVE::VZDump::Common; use PVE::API2::VZDump; use PVE::Cluster; +use PVE::JSONSchema; use base qw(PVE::Jobs::Plugin); @@ -36,6 +37,32 @@ sub options { return $options; } +sub decode_value { + my ($class, $type, $key, $value) = @_; + + if ($key eq 'prune-backups' && !ref($value)) { + $value = PVE::JSONSchema::parse_property_string( + 'prune-backups', + $value, + ); + } + + return $value; +} + +sub encode_value { + my ($class, $type, $key, $value) = @_; + + if ($key eq 'prune-backups' && ref($value) eq 'HASH') { + $value = PVE::JSONSchema::print_property_string( + $value, + 'prune-backups', + ); + } + + return $value; +} + sub run { my ($class, $conf) = @_; -- 2.30.2