[pve-devel] [PATCH pve-ha-manager 1/2] Add service existence and state check helpers
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Oct 12 09:55:40 CEST 2015
Add an exists helper which returns service specific if the resource
is anywhere on the cluster, i.e. can be added.
Also add a check if a service is ha managed.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/HA/Config.pm | 14 ++++++++++++++
src/PVE/HA/Resources.pm | 20 ++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index 0a6dfa5..e54a039 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -174,4 +174,18 @@ sub vm_is_ha_managed {
return undef;
}
+sub service_is_ha_managed {
+ my ($sid, $has_state) = @_;
+
+ my $conf = cfs_read_file($ha_resources_config);
+
+ if (my $vm = $conf->{ids}->{$sid}) {
+ return 1 if !defined($has_state);
+
+ $vm->{state} = 'enabled' if !defined($vm->{state});
+ return $vm->{state} eq $has_state;
+ }
+
+ return undef;
+}
1;
diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index c41fa91..43da82b 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -104,6 +104,10 @@ sub config_file {
die "implement in subclass"
}
+sub exists {
+ die "implement in subclass"
+}
+
sub check_running {
die "implement in subclass";
}
@@ -146,6 +150,14 @@ sub config_file {
return PVE::QemuServer::config_file($vmid, $nodename);
}
+sub exists {
+ my ($class, $vmid) = @_;
+
+ my $vmlist = PVE::Cluster::get_vmlist();
+
+ return defined($vmlist->{ids}->{$vmid});
+}
+
sub start {
my ($class, $haenv, $params) = @_;
@@ -212,6 +224,14 @@ sub config_file {
return PVE::LXC::config_file($vmid, $nodename);
}
+sub exists {
+ my ($class, $vmid) = @_;
+
+ my $vmlist = PVE::Cluster::get_vmlist();
+
+ return defined($vmlist->{ids}->{$vmid});
+}
+
sub start {
my ($class, $haenv, $params) = @_;
--
2.1.4
More information about the pve-devel
mailing list