Reference Guide

12 RESTful Server Configuration with iDRAC RESTful API
Notice that Job ID is a value nested within a dictionary of a dictionary. We will now modify the script to access
the dictionary and then parse the value using regular expressions to obtain the Job ID. The added code for
this purpose is highlighted in the following script:
Script redfish_SCP_export_cifs.v2.py version 2:
#
# Version 2 - Python iDRAC RESTful API script to export
# server configuration profile
#
import requests, json, re
url = 'https://192.168.0.120/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/EI
D_674_Manager.ExportSystemConfiguration'
payload = {"ExportFormat":"XML","ShareParameters":{"Target":"ALL","IPAddress":"1
92.168.0.130",
"ShareName":"cifs_share","ShareType":"CIFS","UserName":"user","Password":"passwo
rd","FileName": "R730_SCP.xml"}}
headers = {'content-type': 'application/json'}
response = requests.post(url, data=json.dumps(payload), headers=headers, verify=
False, auth=('username','password'))
print '- Response status code is: %s' % response.status_code
response_output=response.__dict__
job_id=response_output["headers"]["Location"]
job_id=re.search("JID_.+",job_id).group()
print "- Job ID is: %s" % job_id
Now, execute version 2 and view the returned status code and Job ID:
$ python ./redfish_SCP_export_cifs.v2.py
- Response status code is: 202
- Job ID is: JID_967983367454
$
After a successful export request operation, wait till the export job is complete. This is performed by querying
the RESTful API Task Service until the job completes successfully or indicates an error. We will create a
script to check the job status and then run the script with the Job ID as an input parameter:
Script: rest_SCP_get_job_status.py
import requests, sys
job_id=sys.argv[1]
req = requests.get('https://192.168.0.120/redfish/v1/TaskService/Tasks/%s' % (jo
b_id), auth=("username", "password"), verify=False)
statusCode = req.status_code
print "- Status code is: %s" % statusCode
data = req.json()
message_string=data[u"Messages"]
print "- Job ID = "+data[u"Id"]
print "- Name = "+data[u"Name"]
print "- Message = "+message_string[0][u"Message"]
print "- JobStatus = "+data[u"TaskState"]