all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 1/4] Jobs/VZDump: encode/decode 'prune-backups' where needed
Date: Wed, 10 Nov 2021 15:02:53 +0100	[thread overview]
Message-ID: <20211110140256.1863209-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20211110140256.1863209-1-d.csapak@proxmox.com>

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 <d.csapak@proxmox.com>
---
 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





  reply	other threads:[~2021-11-10 14:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 14:02 [pve-devel] [PATCH manager 0/4] followups for vzdump scheduling2 Dominik Csapak
2021-11-10 14:02 ` Dominik Csapak [this message]
2021-11-10 14:02 ` [pve-devel] [PATCH manager 2/4] ui: dc/BackupEdit: use correct validation Dominik Csapak
2021-11-10 14:02 ` [pve-devel] [PATCH manager 3/4] api: backup/jobs: add comment field to jobs Dominik Csapak
2021-11-10 14:02 ` [pve-devel] [PATCH manager 4/4] ui: dc/Backup: add comment field and column Dominik Csapak
2021-11-10 17:18 ` [pve-devel] [PATCH manager 0/4] followups for vzdump scheduling2 Thomas Lamprecht
2021-11-10 20:37 ` [pve-devel] applied-series: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211110140256.1863209-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal