]> git.proxmox.com Git - pve-ha-manager.git/blame - src/PVE/HA/Resources.pm
cleanup backup & mounted locks after recovery (fixes #1100)
[pve-ha-manager.git] / src / PVE / HA / Resources.pm
CommitLineData
a223f4cc
DM
1package PVE::HA::Resources;
2
3use strict;
4use warnings;
5
6use Data::Dumper;
7use PVE::JSONSchema qw(get_standard_option);
8use PVE::SectionConfig;
9use PVE::HA::Tools;
10
11use base qw(PVE::SectionConfig);
12
13my $defaultData = {
14 propertyList => {
95ea5d67 15 type => { description => "Resource type.", optional => 1 },
73bede9b 16 sid => get_standard_option('pve-ha-resource-or-vm-id',
bf119a50 17 { completion => \&PVE::HA::Tools::complete_sid }),
7a19642e
DM
18 state => {
19 description => "Resource state.",
20 type => 'string',
21 enum => ['enabled', 'disabled'],
22 optional => 1,
95ea5d67 23 default => 'enabled',
7a19642e 24 },
73bede9b
TL
25 group => get_standard_option('pve-ha-group-id',
26 { optional => 1,
27 completion => \&PVE::HA::Tools::complete_group }),
ea4443cc
TL
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 },
a223f4cc
DM
44 comment => {
45 description => "Description.",
46 type => 'string',
47 optional => 1,
48 maxLength => 4096,
49 },
50 },
51};
52
53sub verify_name {
54 my ($class, $name) = @_;
55
56 die "implement this in subclass";
57}
58
59sub private {
60 return $defaultData;
61}
62
95ea5d67
DM
63sub format_section_header {
64 my ($class, $type, $sectionId) = @_;
65
66 my (undef, $name) = split(':', $sectionId, 2);
67
68 return "$type: $name\n";
69}
70
a223f4cc
DM
71sub 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);
85d36c36
DM
80 } else {
81 die "no such resource type '$type'\n";
a223f4cc 82 }
a223f4cc
DM
83 };
84 $errmsg = $@ if $@;
95ea5d67 85 my $config = {}; # to return additional attributes
a223f4cc
DM
86 return ($type, "$type:$name", $errmsg, $config);
87 }
88 return undef;
89}
90
3d60e54f 91sub start {
b865e4cb 92 my ($class, $haenv, $id) = @_;
92bd23c6 93
3d60e54f
TL
94 die "implement in subclass";
95}
96
97sub shutdown {
b865e4cb 98 my ($class, $haenv, $id) = @_;
92bd23c6 99
3d60e54f
TL
100 die "implement in subclass";
101}
102
103sub migrate {
b865e4cb 104 my ($class, $haenv, $id, $target, $online) = @_;
92bd23c6 105
3d60e54f
TL
106 die "implement in subclass";
107}
108
109sub config_file {
92bd23c6
TL
110 my ($class, $id, $nodename) = @_;
111
3d60e54f
TL
112 die "implement in subclass"
113}
114
f06755de
TL
115sub exists {
116 my ($class, $id, $noerr) = @_;
117
118 die "implement in subclass"
119}
120
3d60e54f 121sub check_running {
0d5906f3 122 my ($class, $haenv, $id) = @_;
92bd23c6 123
3d60e54f
TL
124 die "implement in subclass";
125}
126
5dd3ed86
TL
127sub remove_locks {
128 my ($self, $haenv, $id, $locks, $service_node) = @_;
129
130 die "implement in subclass";
131}
132
3d60e54f 133
85d36c36 134# package PVE::HA::Resources::IPAddr;
a223f4cc 135
85d36c36
DM
136# use strict;
137# use warnings;
138# use PVE::Tools qw($IPV4RE $IPV6RE);
a223f4cc 139
85d36c36 140# use base qw(PVE::HA::Resources);
a223f4cc 141
85d36c36
DM
142# sub type {
143# return 'ipaddr';
144# }
a223f4cc 145
85d36c36
DM
146# sub verify_name {
147# my ($class, $name) = @_;
a223f4cc 148
85d36c36
DM
149# die "invalid IP address\n" if $name !~ m!^$IPV6RE|$IPV4RE$!;
150# }
a223f4cc 151
85d36c36
DM
152# sub options {
153# return {
154# state => { optional => 1 },
155# group => { optional => 1 },
156# comment => { optional => 1 },
157# };
158# }
a223f4cc
DM
159
1601;