]>
Commit | Line | Data |
---|---|---|
76c6ee8a DC |
1 | package PVE::Jobs::VZDump; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::INotify; | |
7 | use PVE::VZDump::Common; | |
8 | use PVE::API2::VZDump; | |
9 | use PVE::Cluster; | |
b3422046 | 10 | use PVE::JSONSchema; |
76c6ee8a DC |
11 | |
12 | use base qw(PVE::Jobs::Plugin); | |
13 | ||
14 | sub type { | |
15 | return 'vzdump'; | |
16 | } | |
17 | ||
18 | my $props = PVE::VZDump::Common::json_config_properties(); | |
19 | ||
20 | sub properties { | |
21 | return $props; | |
22 | } | |
23 | ||
24 | sub options { | |
25 | my $options = { | |
26 | enabled => { optional => 1 }, | |
27 | schedule => {}, | |
998b61fb | 28 | comment => { optional => 1 }, |
c61c192e | 29 | 'repeat-missed' => { optional => 1 }, |
76c6ee8a DC |
30 | }; |
31 | foreach my $opt (keys %$props) { | |
32 | if ($props->{$opt}->{optional}) { | |
33 | $options->{$opt} = { optional => 1 }; | |
34 | } else { | |
35 | $options->{$opt} = {}; | |
36 | } | |
37 | } | |
38 | ||
39 | return $options; | |
40 | } | |
41 | ||
b3422046 DC |
42 | sub decode_value { |
43 | my ($class, $type, $key, $value) = @_; | |
44 | ||
93880785 FE |
45 | if ((my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key}) && !ref($value)) { |
46 | $value = PVE::JSONSchema::parse_property_string($format, $value); | |
b3422046 DC |
47 | } |
48 | ||
49 | return $value; | |
50 | } | |
51 | ||
52 | sub encode_value { | |
53 | my ($class, $type, $key, $value) = @_; | |
54 | ||
93880785 FE |
55 | if ((my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key}) && ref($value) eq 'HASH') { |
56 | $value = PVE::JSONSchema::print_property_string($value, $format); | |
b3422046 DC |
57 | } |
58 | ||
59 | return $value; | |
60 | } | |
61 | ||
76c6ee8a DC |
62 | sub run { |
63 | my ($class, $conf) = @_; | |
64 | ||
65 | # remove all non vzdump related options | |
66 | foreach my $opt (keys %$conf) { | |
67 | delete $conf->{$opt} if !defined($props->{$opt}); | |
68 | } | |
69 | ||
93880785 FE |
70 | # Required as string parameters |
71 | for my $key (keys $PVE::VZDump::Common::PROPERTY_STRINGS->%*) { | |
72 | if ($conf->{$key} && ref($conf->{$key}) eq 'HASH') { | |
73 | my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key}; | |
74 | $conf->{$key} = PVE::JSONSchema::print_property_string($conf->{$key}, $format); | |
75 | } | |
4048af34 | 76 | } |
80ea4443 | 77 | |
76c6ee8a DC |
78 | $conf->{quiet} = 1; # do not write to stdout/stderr |
79 | ||
80 | PVE::Cluster::cfs_update(); # refresh vmlist | |
81 | ||
82 | return PVE::API2::VZDump->vzdump($conf); | |
83 | } | |
84 | ||
85 | 1; |