2.6.4.2 Python

Continuing on from the previous example, in Section 2.6.3, “Listing Servers”, the session object can be used to submit a POST request containing the agent password specified as a simple string:

...
uri_params={'serverName':'1.example.com', 'takeOwnershipIfUnowned':'True'}
data='p4ssword'
r=s.post(baseUri+'/Server/discover', data, params=uri_params)

If the request has been formatted correctly and the API accepts it, the JSON response returned contains information about the job that has been created to carry out the process requested. You can easily obtain the job URI from the response data and use it to track job status with the wait_for_job function:

job=r.json()
print 'Job: {name} for {server}'.format(name=job['id']['name'],server='1.example.org')
joburi=job['id']['uri']
wait_for_job(joburi,s)
Note

ID objects include the URI by which the complete object can be referenced. We can easily obtain this URI to perform another query against the API for the Job object so that we can track its status. In this example we reference the wait_for_job function, which has not been defined. Before you attempt to use this function, refer to Section 2.6.5, “Working with Jobs” to find out how you should go about defining it.