pve-manager/PVE/Jobs/Plugin.pm
Dominik Csapak b34220461d Jobs/VZDump: encode/decode 'prune-backups' where needed
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>
2021-11-10 16:11:42 +01:00

77 lines
1.5 KiB
Perl

package PVE::Jobs::Plugin;
use strict;
use warnings;
use PVE::Cluster qw(cfs_register_file);
use base qw(PVE::SectionConfig);
cfs_register_file('jobs.cfg',
sub { __PACKAGE__->parse_config(@_); },
sub { __PACKAGE__->write_config(@_); });
my $defaultData = {
propertyList => {
type => { description => "Section type." },
id => {
description => "The ID of the VZDump job.",
type => 'string',
format => 'pve-configid',
},
enabled => {
description => "Determines if the job is enabled.",
type => 'boolean',
default => 1,
optional => 1,
},
schedule => {
description => "Backup schedule. The format is a subset of `systemd` calendar events.",
type => 'string', format => 'pve-calendar-event',
maxLength => 128,
},
},
};
sub private {
return $defaultData;
}
sub parse_config {
my ($class, $filename, $raw) = @_;
my $cfg = $class->SUPER::parse_config($filename, $raw);
foreach my $id (sort keys %{$cfg->{ids}}) {
my $data = $cfg->{ids}->{$id};
$data->{id} = $id;
$data->{enabled} //= 1;
}
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
die "not implemented";
}
1;