|
|
7c014a |
From 75a74debba2205547d8eefae221221c2c71d99ce Mon Sep 17 00:00:00 2001
|
|
|
7c014a |
From: Jose Delarosa <jose.delarosa@dell.com>
|
|
|
7c014a |
Date: Mon, 15 Apr 2019 12:46:42 -0500
|
|
|
7c014a |
Subject: [PATCH] fence_redfish: add headers to HTTP methods
|
|
|
7c014a |
|
|
|
7c014a |
* Needed for full compliance with Redfish spec.
|
|
|
7c014a |
* May cause errors in some devices if not sent.
|
|
|
7c014a |
---
|
|
|
7c014a |
agents/redfish/fence_redfish.py | 13 +++++++++----
|
|
|
7c014a |
1 file changed, 9 insertions(+), 4 deletions(-)
|
|
|
7c014a |
|
|
|
7c014a |
diff --git a/agents/redfish/fence_redfish.py b/agents/redfish/fence_redfish.py
|
|
|
7c014a |
index f1424232..390a4827 100644
|
|
|
7c014a |
--- a/agents/redfish/fence_redfish.py
|
|
|
7c014a |
+++ b/agents/redfish/fence_redfish.py
|
|
|
7c014a |
@@ -16,6 +16,11 @@
|
|
|
7c014a |
from fencing import *
|
|
|
7c014a |
from fencing import fail_usage, run_delay
|
|
|
7c014a |
|
|
|
7c014a |
+GET_HEADERS = {'accept': 'application/json', 'OData-Version': '4.0'}
|
|
|
7c014a |
+POST_HEADERS = {'content-type': 'application/json', 'accept': 'application/json',
|
|
|
7c014a |
+ 'OData-Version': '4.0'}
|
|
|
7c014a |
+
|
|
|
7c014a |
+
|
|
|
7c014a |
def get_power_status(conn, options):
|
|
|
7c014a |
response = send_get_request(options, options["--systems-uri"])
|
|
|
7c014a |
if response['ret'] is False:
|
|
|
7c014a |
@@ -40,7 +45,6 @@ def set_power_status(conn, options):
|
|
|
7c014a |
}[options["--action"]]
|
|
|
7c014a |
|
|
|
7c014a |
payload = {'ResetType': action}
|
|
|
7c014a |
- headers = {'content-type': 'application/json'}
|
|
|
7c014a |
|
|
|
7c014a |
# Search for 'Actions' key and extract URI from it
|
|
|
7c014a |
response = send_get_request(options, options["--systems-uri"])
|
|
|
7c014a |
@@ -49,7 +53,7 @@ def set_power_status(conn, options):
|
|
|
7c014a |
data = response['data']
|
|
|
7c014a |
action_uri = data["Actions"]["#ComputerSystem.Reset"]["target"]
|
|
|
7c014a |
|
|
|
7c014a |
- response = send_post_request(options, action_uri, payload, headers)
|
|
|
7c014a |
+ response = send_post_request(options, action_uri, payload)
|
|
|
7c014a |
if response['ret'] is False:
|
|
|
7c014a |
fail_usage("Error sending power command")
|
|
|
7c014a |
return
|
|
|
7c014a |
@@ -58,17 +62,18 @@ def send_get_request(options, uri):
|
|
|
7c014a |
full_uri = "https://" + options["--ip"] + ":" + str(options["--ipport"]) + uri
|
|
|
7c014a |
try:
|
|
|
7c014a |
resp = requests.get(full_uri, verify=not "--ssl-insecure" in options,
|
|
|
7c014a |
+ headers=GET_HEADERS,
|
|
|
7c014a |
auth=(options["--username"], options["--password"]))
|
|
|
7c014a |
data = resp.json()
|
|
|
7c014a |
except Exception as e:
|
|
|
7c014a |
fail_usage("Failed: send_get_request: " + str(e))
|
|
|
7c014a |
return {'ret': True, 'data': data}
|
|
|
7c014a |
|
|
|
7c014a |
-def send_post_request(options, uri, payload, headers):
|
|
|
7c014a |
+def send_post_request(options, uri, payload):
|
|
|
7c014a |
full_uri = "https://" + options["--ip"] + ":" + str(options["--ipport"]) + uri
|
|
|
7c014a |
try:
|
|
|
7c014a |
requests.post(full_uri, data=json.dumps(payload),
|
|
|
7c014a |
- headers=headers, verify=not "--ssl-insecure" in options,
|
|
|
7c014a |
+ headers=POST_HEADERS, verify=not "--ssl-insecure" in options,
|
|
|
7c014a |
auth=(options["--username"], options["--password"]))
|
|
|
7c014a |
except Exception as e:
|
|
|
7c014a |
fail_usage("Failed: send_post_request: " + str(e))
|