forked from dell/iDRAC-Redfish-Scripting
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to handle older Redfish versions
- Loading branch information
Showing
1 changed file
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# | ||
# | ||
# _author_ = Texas Roemer <[email protected]> | ||
# _version_ = 2.0 | ||
# _version_ = 3.0 | ||
# | ||
# Copyright (c) 2020, Dell, Inc. | ||
# | ||
|
@@ -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: | ||
|
@@ -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"]: | ||
|