]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
Resource/API: abort early if resource in error state
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 24 Jan 2017 16:54:03 +0000 (17:54 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 14 Mar 2017 09:45:57 +0000 (10:45 +0100)
If a service is in error state the single state change command that
can make sense is setting the disabled request state.
Thus abort on all other commands early to enhance user experience.

src/PVE/API2/HA/Resources.pm

index 621c9e6a004ee080f6104404b6e46c87e8dfb02a..d57824bc8c854798b9a12615230b23f1bccadffd 100644 (file)
@@ -34,6 +34,18 @@ my $api_copy_config = sub {
     return $scfg;
 };
 
+sub check_service_state {
+    my ($sid, $req_state) = @_;
+
+    my $service_status = PVE::HA::Config::get_service_status($sid);
+    if ($service_status->{managed} && $service_status->{state} eq 'error') {
+       # service in error state, must get disabled before new state request
+       # can be executed
+       return if defined($req_state) && $req_state eq 'disabled';
+       die "service '$sid' in error state, must be disabled and fixed first\n";
+    }
+}
+
 __PACKAGE__->register_method ({
     name => 'index',
     path => '',
@@ -187,6 +199,8 @@ __PACKAGE__->register_method ({
                if !$group_cfg->{ids}->{$group};
        }
 
+       check_service_state($sid, $param->{state});
+
        PVE::HA::Config::lock_ha_domain(
            sub {
 
@@ -288,6 +302,8 @@ __PACKAGE__->register_method ({
 
        PVE::HA::Config::service_is_ha_managed($sid);
 
+       check_service_state($sid);
+
        PVE::HA::Config::queue_crm_commands("migrate $sid $param->{node}");
            
        return undef;
@@ -319,6 +335,8 @@ __PACKAGE__->register_method ({
 
        PVE::HA::Config::service_is_ha_managed($sid);
 
+       check_service_state($sid);
+
        PVE::HA::Config::queue_crm_commands("relocate $sid $param->{node}");
            
        return undef;