Blame SOURCES/bz1760224-fence_vmware_rest-improve-logging.patch

6147c0
From a128c296c18faa1b58c3f067370bde64e7c49dae Mon Sep 17 00:00:00 2001
6147c0
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
6147c0
Date: Wed, 9 Oct 2019 14:35:48 +0200
6147c0
Subject: [PATCH] fence_vmware_rest: improve logging
6147c0
6147c0
---
6147c0
 agents/vmware_rest/fence_vmware_rest.py | 23 +++++++++++++++++++----
6147c0
 1 file changed, 19 insertions(+), 4 deletions(-)
6147c0
6147c0
diff --git a/agents/vmware_rest/fence_vmware_rest.py b/agents/vmware_rest/fence_vmware_rest.py
6147c0
index 53b4066d..cd99b4ac 100644
6147c0
--- a/agents/vmware_rest/fence_vmware_rest.py
6147c0
+++ b/agents/vmware_rest/fence_vmware_rest.py
6147c0
@@ -11,7 +11,11 @@
6147c0
 state = {"POWERED_ON": "on", 'POWERED_OFF': "off", 'SUSPENDED': "off"}
6147c0
 
6147c0
 def get_power_status(conn, options):
6147c0
-	res = send_command(conn, "vcenter/vm?filter.names={}".format(options["--plug"]))["value"]
6147c0
+	try:
6147c0
+		res = send_command(conn, "vcenter/vm?filter.names={}".format(options["--plug"]))["value"]
6147c0
+	except Exception as e:
6147c0
+		logging.debug("Failed: {}".format(e))
6147c0
+		fail(EC_STATUS)
6147c0
 
6147c0
 	if len(res) == 0:
6147c0
 		fail(EC_STATUS)
6147c0
@@ -28,12 +32,20 @@ def set_power_status(conn, options):
6147c0
 		"off" : "stop"
6147c0
 	}[options["--action"]]
6147c0
 
6147c0
-	send_command(conn, "vcenter/vm/{}/power/{}".format(options["id"], action), "POST")
6147c0
+	try:
6147c0
+		send_command(conn, "vcenter/vm/{}/power/{}".format(options["id"], action), "POST")
6147c0
+	except Exception as e:
6147c0
+		logging.debug("Failed: {}".format(e))
6147c0
+		fail(EC_STATUS)
6147c0
 
6147c0
 def get_list(conn, options):
6147c0
 	outlets = {}
6147c0
 
6147c0
-	res = send_command(conn, "vcenter/vm")
6147c0
+	try:
6147c0
+		res = send_command(conn, "vcenter/vm")
6147c0
+	except:
6147c0
+		logging.debug("Failed: {}".format(e))
6147c0
+		fail(EC_STATUS)
6147c0
 
6147c0
 	for r in res["value"]:
6147c0
 		outlets[r["name"]] = ("", state[r["power_state"]])
6147c0
@@ -87,7 +99,10 @@ def connect(opt):
6147c0
 	return conn
6147c0
 
6147c0
 def disconnect(conn):
6147c0
-	send_command(conn, "com/vmware/cis/session", "DELETE")
6147c0
+	try:
6147c0
+		send_command(conn, "com/vmware/cis/session", "DELETE")
6147c0
+	except Exception as e:
6147c0
+		logging.debug("Failed: {}".format(e))
6147c0
 	conn.close()
6147c0
 
6147c0
 def send_command(conn, command, method="GET"):