]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Resources.pm
cleanup backup & mounted locks after recovery (fixes #1100)
[pve-ha-manager.git] / src / PVE / HA / Resources.pm
1 package PVE::HA::Resources;
2
3 use strict;
4 use warnings;
5
6 use Data::Dumper;
7 use PVE::JSONSchema qw(get_standard_option);
8 use PVE::SectionConfig;
9 use PVE::HA::Tools;
10
11 use base qw(PVE::SectionConfig);
12
13 my $defaultData = {
14 propertyList => {
15 type => { description => "Resource type.", optional => 1 },
16 sid => get_standard_option('pve-ha-resource-or-vm-id',
17 { completion => \&PVE::HA::Tools::complete_sid }),
18 state => {
19 description => "Resource state.",
20 type => 'string',
21 enum => ['enabled', 'disabled'],
22 optional => 1,
23 default => 'enabled',
24 },
25 group => get_standard_option('pve-ha-group-id',
26 { optional => 1,
27 completion => \&PVE::HA::Tools::complete_group }),
28 max_restart => {
29 description => "Maximal number of tries to restart the service on".
30 " a node after its start failed.",
31 type => 'integer',
32 optional => 1,
33 default => 1,
34 minimum => 0,
35 },
36 max_relocate => {
37 description => "Maximal number of service relocate tries when a".
38 " service failes to start.",
39 type => 'integer',
40 optional => 1,
41 default => 1,
42 minimum => 0,
43 },
44 comment => {
45 description => "Description.",
46 type => 'string',
47 optional => 1,
48 maxLength => 4096,
49 },
50 },
51 };
52
53 sub verify_name {
54 my ($class, $name) = @_;
55
56 die "implement this in subclass";
57 }
58
59 sub private {
60 return $defaultData;
61 }
62
63 sub format_section_header {
64 my ($class, $type, $sectionId) = @_;
65
66 my (undef, $name) = split(':', $sectionId, 2);
67
68 return "$type: $name\n";
69 }
70
71 sub parse_section_header {
72 my ($class, $line) = @_;
73
74 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
75 my ($type, $name) = (lc($1), $2);
76 my $errmsg = undef; # set if you want to skip whole section
77 eval {
78 if (my $plugin = $defaultData->{plugins}->{$type}) {
79 $plugin->verify_name($name);
80 } else {
81 die "no such resource type '$type'\n";
82 }
83 };
84 $errmsg = $@ if $@;
85 my $config = {}; # to return additional attributes
86 return ($type, "$type:$name", $errmsg, $config);
87 }
88 return undef;
89 }
90
91 sub start {
92 my ($class, $haenv, $id) = @_;
93
94 die "implement in subclass";
95 }
96
97 sub shutdown {
98 my ($class, $haenv, $id) = @_;
99
100 die "implement in subclass";
101 }
102
103 sub migrate {
104 my ($class, $haenv, $id, $target, $online) = @_;
105
106 die "implement in subclass";
107 }
108
109 sub config_file {
110 my ($class, $id, $nodename) = @_;
111
112 die "implement in subclass"
113 }
114
115 sub exists {
116 my ($class, $id, $noerr) = @_;
117
118 die "implement in subclass"
119 }
120
121 sub check_running {
122 my ($class, $haenv, $id) = @_;
123
124 die "implement in subclass";
125 }
126
127 sub remove_locks {
128 my ($self, $haenv, $id, $locks, $service_node) = @_;
129
130 die "implement in subclass";
131 }
132
133
134 # package PVE::HA::Resources::IPAddr;
135
136 # use strict;
137 # use warnings;
138 # use PVE::Tools qw($IPV4RE $IPV6RE);
139
140 # use base qw(PVE::HA::Resources);
141
142 # sub type {
143 # return 'ipaddr';
144 # }
145
146 # sub verify_name {
147 # my ($class, $name) = @_;
148
149 # die "invalid IP address\n" if $name !~ m!^$IPV6RE|$IPV4RE$!;
150 # }
151
152 # sub options {
153 # return {
154 # state => { optional => 1 },
155 # group => { optional => 1 },
156 # comment => { optional => 1 },
157 # };
158 # }
159
160 1;