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