fence-agents/bz1760224-fence_vmware_rest-improve-logging.patch

62 lines
1.9 KiB
Diff
Raw Permalink Normal View History

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