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

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