]> git.proxmox.com Git - pve-manager.git/commitdiff
Jobs/VZDump: encode/decode 'prune-backups' where needed
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 10 Nov 2021 14:02:53 +0000 (15:02 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 10 Nov 2021 15:11:42 +0000 (16:11 +0100)
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
PVE/Jobs/VZDump.pm

index 69c31cf28e2b72a89803963a66dbc42b013e9719..9cf7f98de1c5a5d66370368f073ff30bf305aec6 100644 (file)
@@ -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
index 043b7ace120ca82996967824b036f4fa7248a2be..87733e74f63ca7ae2ac251a0cca3429596ffd338 100644 (file)
@@ -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) = @_;