mirror of
git://git.proxmox.com/git/pve-ha-manager.git
synced 2025-01-07 21:18:00 +03:00
factor out service configured/delete helpers
those differ from the "managed" service in that that they do not check the state at all, the just check if, or respectively delete, a SID is in the config or not. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
2331a744f9
commit
79fcbe00ed
@ -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;
|
||||
}});
|
||||
|
@ -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) = @_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user