Blob Blame History Raw
From 0aacfcf209c473ab4c1fff4de653a673b92484de Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac@redhat.com>
Date: Wed, 19 Aug 2015 09:55:06 +0200
Subject: [PATCH] fence_virsh: Add --missing-as-off option

Resolves: rhbz#1254821
---
 fence/agents/virsh/fence_virsh.py   | 4 +++-
 tests/data/metadata/fence_virsh.xml | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index 0a94136..24d360c 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -54,6 +54,8 @@ def get_power_status(conn, options):
 	for line in conn.before.splitlines():
 		if line.strip() in ["running", "blocked", "idle", "no state", "paused"]:
 			return "on"
+		if "error: failed to get domain" in line.strip() and options.has_key("missing_as_off"):
+			return "off"
 		if "error:" in line.strip():
 			fail_usage("Failed: You have to enter existing name/UUID of virtual machine!")
 
@@ -68,7 +70,7 @@ def set_power_status(conn, options):
 	time.sleep(int(options["--power-wait"]))
 
 def main():
-	device_opt = ["ipaddr", "login", "passwd", "cmd_prompt", "secure", "port", "sudo"]
+	device_opt = ["ipaddr", "login", "passwd", "cmd_prompt", "secure", "port", "sudo", "missing_as_off"]
 
 	atexit.register(atexit_handler)
 
diff --git a/tests/data/metadata/fence_virsh.xml b/tests/data/metadata/fence_virsh.xml
index 642c72e..d664fc4 100644
--- a/tests/data/metadata/fence_virsh.xml
+++ b/tests/data/metadata/fence_virsh.xml
@@ -105,6 +105,11 @@ By default, virsh needs root account to do properly work. So you must allow ssh
 		<content type="string" default="5"  />
 		<shortdesc lang="en">Wait X seconds for cmd prompt after login</shortdesc>
 	</parameter>
+	<parameter name="missing_as_off" unique="0" required="0">
+		<getopt mixed="--missing-as-off" />
+		<content type="boolean"  />
+		<shortdesc lang="en">Missing port returns OFF instead of failure</shortdesc>
+	</parameter>
 	<parameter name="power_timeout" unique="0" required="0">
 		<getopt mixed="--power-timeout=[seconds]" />
 		<content type="string" default="20"  />