]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/HA/Resources.pm
cleanup backup & mounted locks after recovery (fixes #1100)
[pve-ha-manager.git] / src / PVE / HA / Resources.pm
index 441481be31f04608461a65f5e9964fc456980b9b..96d2f8fe95faa9c66b50be3748ebb6237261c1b3 100644 (file)
@@ -12,19 +12,35 @@ use base qw(PVE::SectionConfig);
 
 my $defaultData = {
     propertyList => {
-       type => { description => "Resource type." },
-       name => {
-           description => "Resource name.",
-           type => 'string',
-           optional => 1,
-       },
+       type => { description => "Resource type.", optional => 1 },
+       sid => get_standard_option('pve-ha-resource-or-vm-id',
+                                  { completion => \&PVE::HA::Tools::complete_sid }),
        state => {
            description => "Resource state.",
            type => 'string',
            enum => ['enabled', 'disabled'],
            optional => 1,
+           default => 'enabled',
+       },
+       group => get_standard_option('pve-ha-group-id',
+                                   { optional => 1,
+                                     completion => \&PVE::HA::Tools::complete_group }),
+       max_restart => {
+           description => "Maximal number of tries to restart the service on".
+                         " a node after its start failed.",
+           type => 'integer',
+           optional => 1,
+           default => 1,
+           minimum => 0,
+       },
+       max_relocate => {
+           description => "Maximal number of service relocate tries when a".
+                         " service failes to start.",
+           type => 'integer',
+           optional => 1,
+           default => 1,
+           minimum => 0,
        },
-       group => get_standard_option('pve-ha-group-id'),
        comment => {
            description => "Description.",
            type => 'string',
@@ -44,6 +60,14 @@ sub private {
     return $defaultData;
 }
 
+sub format_section_header {
+    my ($class, $type, $sectionId) = @_;
+
+    my (undef, $name) = split(':', $sectionId, 2);
+    
+    return "$type: $name\n";
+}
+
 sub parse_section_header {
     my ($class, $line) = @_;
 
@@ -53,68 +77,84 @@ sub parse_section_header {
        eval {
            if (my $plugin = $defaultData->{plugins}->{$type}) {
                $plugin->verify_name($name);
+           } else {
+               die "no such resource type '$type'\n";
            }
-           # fixme: ?
-           #PVE::JSONSchema::pve_verify_configid($name);
        };
        $errmsg = $@ if $@;
-       my $config = {
-           name => $name,
-       }; # to return additional attributes
+       my $config = {}; # to return additional attributes
        return ($type, "$type:$name", $errmsg, $config);
     }
     return undef;
 }
 
-package PVE::HA::Resources::PVEVM;
+sub start {
+    my ($class, $haenv, $id) = @_;
 
-use strict;
-use warnings;
+    die "implement in subclass";
+}
 
-use base qw(PVE::HA::Resources);
+sub shutdown {
+    my ($class, $haenv, $id) = @_;
 
-sub type {
-    return 'pvevm';
+    die "implement in subclass";
 }
 
-sub verify_name {
-    my ($class, $name) = @_;
+sub migrate {
+    my ($class, $haenv, $id, $target, $online) = @_;
 
-    die "invalid VMID\n" if $name !~ m/^[1-9][0-0]+$/;
+    die "implement in subclass";
 }
 
-sub options {
-    return {
-       name => {},
-       group => { optional => 1 },
-       comment => { optional => 1 },
-    };
+sub config_file {
+    my ($class, $id, $nodename) = @_;
+
+    die "implement in subclass"
 }
 
-package PVE::HA::Resources::IPAddr;
+sub exists {
+    my ($class, $id, $noerr) = @_;
 
-use strict;
-use warnings;
-use PVE::Tools qw($IPV4RE $IPV6RE);
+    die "implement in subclass"
+}
 
-use base qw(PVE::HA::Resources);
+sub check_running {
+    my ($class, $haenv, $id) = @_;
 
-sub type {
-    return 'ipaddr';
+    die "implement in subclass";
 }
 
-sub verify_name {
-    my ($class, $name) = @_;
+sub remove_locks {
+    my ($self, $haenv, $id, $locks, $service_node) = @_;
 
-    die "invalid IP address\n" if $name !~ m!^$IPV6RE|$IPV4RE$!;
+    die "implement in subclass";
 }
 
-sub options {
-    return {
-       name => {},
-       group => { optional => 1 },
-       comment => { optional => 1 },
-    };
-}
+
+# package PVE::HA::Resources::IPAddr;
+
+# use strict;
+# use warnings;
+# use PVE::Tools qw($IPV4RE $IPV6RE);
+
+# use base qw(PVE::HA::Resources);
+
+# sub type {
+#     return 'ipaddr';
+# }
+
+# sub verify_name {
+#     my ($class, $name) = @_;
+
+#     die "invalid IP address\n" if $name !~ m!^$IPV6RE|$IPV4RE$!;
+# }
+
+# sub options {
+#     return {
+#      state => { optional => 1 },
+#      group => { optional => 1 },
+#      comment => { optional => 1 },
+#     };
+# }
 
 1;