]>
Commit | Line | Data |
---|---|---|
76c6ee8a DC |
1 | package PVE::Jobs::Plugin; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::Cluster qw(cfs_register_file); | |
7 | ||
8 | use base qw(PVE::SectionConfig); | |
9 | ||
10 | cfs_register_file('jobs.cfg', | |
11 | sub { __PACKAGE__->parse_config(@_); }, | |
12 | sub { __PACKAGE__->write_config(@_); }); | |
13 | ||
14 | my $defaultData = { | |
15 | propertyList => { | |
16 | type => { description => "Section type." }, | |
17 | id => { | |
18 | description => "The ID of the VZDump job.", | |
19 | type => 'string', | |
20 | format => 'pve-configid', | |
21 | }, | |
22 | enabled => { | |
23 | description => "Determines if the job is enabled.", | |
24 | type => 'boolean', | |
25 | default => 1, | |
26 | optional => 1, | |
27 | }, | |
28 | schedule => { | |
29 | description => "Backup schedule. The format is a subset of `systemd` calendar events.", | |
30 | type => 'string', format => 'pve-calendar-event', | |
31 | maxLength => 128, | |
32 | }, | |
998b61fb DC |
33 | comment => { |
34 | optional => 1, | |
35 | type => 'string', | |
36 | description => "Description for the Job.", | |
37 | maxLength => 512, | |
38 | }, | |
76c6ee8a DC |
39 | }, |
40 | }; | |
41 | ||
42 | sub private { | |
43 | return $defaultData; | |
44 | } | |
45 | ||
46 | sub parse_config { | |
47 | my ($class, $filename, $raw) = @_; | |
48 | ||
49 | my $cfg = $class->SUPER::parse_config($filename, $raw); | |
50 | ||
51 | foreach my $id (sort keys %{$cfg->{ids}}) { | |
52 | my $data = $cfg->{ids}->{$id}; | |
53 | ||
54 | $data->{id} = $id; | |
55 | $data->{enabled} //= 1; | |
998b61fb DC |
56 | |
57 | if (defined($data->{comment})) { | |
58 | $data->{comment} = PVE::Tools::decode_text($data->{comment}); | |
59 | } | |
76c6ee8a DC |
60 | } |
61 | ||
62 | return $cfg; | |
63 | } | |
64 | ||
b3422046 DC |
65 | # call the plugin specific decode/encode code |
66 | sub decode_value { | |
67 | my ($class, $type, $key, $value) = @_; | |
68 | ||
69 | my $plugin = __PACKAGE__->lookup($type); | |
70 | return $plugin->decode_value($type, $key, $value); | |
71 | } | |
72 | ||
73 | sub encode_value { | |
74 | my ($class, $type, $key, $value) = @_; | |
75 | ||
76 | my $plugin = __PACKAGE__->lookup($type); | |
77 | return $plugin->encode_value($type, $key, $value); | |
78 | } | |
79 | ||
998b61fb DC |
80 | sub write_config { |
81 | my ($class, $filename, $cfg) = @_; | |
82 | ||
83 | for my $job (values $cfg->{ids}->%*) { | |
84 | if (defined($job->{comment})) { | |
85 | $job->{comment} = PVE::Tools::encode_text($job->{comment}); | |
86 | } | |
87 | } | |
88 | ||
89 | $class->SUPER::write_config($filename, $cfg); | |
90 | } | |
91 | ||
76c6ee8a DC |
92 | sub run { |
93 | my ($class, $cfg) = @_; | |
94 | # implement in subclass | |
95 | die "not implemented"; | |
96 | } | |
97 | ||
98 | 1; |