[pve-devel] [PATCH v2 pve-ha-manager 3/5] Add resource existence check helper

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Oct 12 15:04:40 CEST 2015


Add a helper to the resource class which returns service specific if
the resource exists on the cluster, i.e. can be added.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Resources.pm | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index c415c3c..5018cb1 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -112,6 +112,12 @@ sub config_file {
     die "implement in subclass"
 }
 
+sub exists {
+    my ($class, $id, $noerr) = @_;
+
+    die "implement in subclass"
+}
+
 sub check_running {
     my ($class, $id) = @_;
 
@@ -156,6 +162,19 @@ sub config_file {
     return PVE::QemuServer::config_file($vmid, $nodename);
 }
 
+sub exists {
+    my ($class, $vmid, $noerr) = @_;
+
+    my $vmlist = PVE::Cluster::get_vmlist();
+
+    if(!defined($vmlist->{ids}->{$vmid})) {
+	die "resource 'vm:$vmid' does not exists in cluster\n" if !$noerr;
+	return undef;
+    } else {
+	return 1;
+    }
+}
+
 sub start {
     my ($class, $haenv, $params) = @_;
 
@@ -222,6 +241,19 @@ sub config_file {
     return PVE::LXC::config_file($vmid, $nodename);
 }
 
+sub exists {
+    my ($class, $vmid, $noerr) = @_;
+
+    my $vmlist = PVE::Cluster::get_vmlist();
+
+    if(!defined($vmlist->{ids}->{$vmid})) {
+	die "resource 'ct:$vmid' does not exists in cluster\n" if !$noerr;
+	return undef;
+    } else {
+	return 1;
+    }
+}
+
 sub start {
     my ($class, $haenv, $params) = @_;
 
-- 
2.1.4





More information about the pve-devel mailing list