Blame SOURCES/bz1704228-fence_redfish-full-redfish-spec-compliance.patch

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