Skip to content

Commit

Permalink
Added support to handle older Redfish versions
Browse files Browse the repository at this point in the history
  • Loading branch information
texroemer authored Apr 22, 2021
1 parent ac45a9c commit 0ac53dd
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Redfish Python/CreateXAuthTokenSessionREDFISH.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
#
# _author_ = Texas Roemer <[email protected]>
# _version_ = 2.0
# _version_ = 3.0
#
# Copyright (c) 2020, Dell, Inc.
#
Expand Down Expand Up @@ -38,12 +38,32 @@
idrac_username=args["u"]
idrac_password=args["p"]

def get_redfish_version():
global redfish_version
response = requests.get('https://%s/redfish/v1' % idrac_ip,verify=False,auth=(idrac_username, idrac_password))
data = response.json()
if response.status_code == 401:
print("\n- WARNING, status code %s returned. Incorrect iDRAC username/password or invalid privilege detected." % response.status_code)
sys.exit(1)
elif response.status_code != 200:
print("\n- WARNING, GET request failed to get Redfish version, status code %s returned" % response.status_code)
sys.exit(1)
else:
pass
redfish_version = int(data["RedfishVersion"].replace(".",""))

def create_x_auth_session():
url = 'https://%s/redfish/v1/SessionService/Sessions' % idrac_ip
if redfish_version >= 160:
url = 'https://%s/redfish/v1/SessionService/Sessions' % idrac_ip
elif redfish_version < 160:
url = 'https://%s/redfish/v1/Sessions' % idrac_ip
else:
print("- INFO, unable to select URI based off Redfish version")
sys.exit()
payload = {"UserName":args["u"],"Password":args["p"]}
headers = {'content-type': 'application/json'}
response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False)
data = response.json()
if response.status_code == 201:
print("\n- PASS, successfuly created X auth session")
else:
Expand Down Expand Up @@ -145,6 +165,7 @@ def delete_x_auth_session():


if __name__ == "__main__":
get_redfish_version()
if args["c"]:
create_x_auth_session()
elif args["g"] and args["t"]:
Expand Down

0 comments on commit 0ac53dd

Please sign in to comment.