diff --git a/src/PVE/API2/HA/Resources.pm b/src/PVE/API2/HA/Resources.pm index 5c11d8b..2c62f5e 100644 --- a/src/PVE/API2/HA/Resources.pm +++ b/src/PVE/API2/HA/Resources.pm @@ -264,21 +264,11 @@ __PACKAGE__->register_method ({ my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid')); - my $cfg = PVE::HA::Config::read_resources_config(); - - # cannot use service_is_ha_managed as it ignores 'ignored' services, - # see bug report #1602 - if (!defined($cfg->{ids}) || !defined($cfg->{ids}->{$sid})) { + if (!PVE::HA::Config::service_is_configured($sid)) { die "cannot delete service '$sid', not HA managed!\n"; } - PVE::HA::Config::lock_ha_domain(sub { - - $cfg = PVE::HA::Config::read_resources_config(); - delete $cfg->{ids}->{$sid} or die "'$sid' not configured!\n"; - PVE::HA::Config::write_resources_config($cfg); - - }, "delete resource failed"); + PVE::HA::Config::delete_service_from_config($sid); return undef; }}); diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm index e4b7181..993b456 100644 --- a/src/PVE/HA/Config.pm +++ b/src/PVE/HA/Config.pm @@ -288,6 +288,34 @@ my $service_check_ha_state = sub { return undef; }; +# cannot use service_is_ha_managed as it skips 'ignored' services, see bug #1602 +sub service_is_configured { + my ($sid) = @_; + + my $conf = read_resources_config(); + if (defined($conf->{ids}) && defined($conf->{ids}->{$sid})) { + return 1; + } + return 0; +} + +# graceful, as long as locking + cfs_write works +sub delete_service_from_config { + my ($sid) = @_; + + return 1 if !service_is_configured($sid); + + my $res; + PVE::HA::Config::lock_ha_domain(sub { + my $conf = read_resources_config(); + $res = delete $conf->{ids}->{$sid}; + write_resources_config($conf); + + }, "delete resource failed"); + + return !!$res; +} + sub vm_is_ha_managed { my ($vmid, $has_state) = @_;