-
Notifications
You must be signed in to change notification settings - Fork 180
Quick Start
This is a basic detailed breakdown of quickstart.py examples. This will cover object creation and a simple call to the API.
Make sure that redfish library is imported.
import redfish
The very first thing that needs to be done for a restful request is to create a redfish object.
A Redfish Rest object instance is created by calling the redfish_client method of the imported redfish library. The redfish_client method returns an instance of the Redfish RESTful client and takes as parameters hostname/ ip address, user name, password, default rest prefix ('/redfish/v1') and other optional arguments.
REST_OBJ = redfish.redfish_client(base_url=host,username=login_account,
password=login_password, default_prefix='/redfish/v1')
Next the rest object's login method is called to initiate a rest session. The parameters for the login method are user name, password and login type (default is Basic authentication). For "session" login, a session key is generated through a rest request.
REST_OBJ.login(auth="session")
Please remember to call logout method once the session is completed.
This is a very simple request example that shows the basic libraries involved and how to properly form the request. The following example performs a GET operation on the systems resource (/redfish/v1/systems/1) using the Restful API. It does an HTTP GET request on the SSL(HTTPS) port (typically 443 but can be configured to use another port as well). The interface is not available over open HTTP (port 80), so SSL handshake must be used.
After creating a Redfish object as mentioned above in Create a Redfish Object section followed by a login session.
Next the Redfish object's get method is called with the system uri (/redfish/v1/systems/1) as the parameter. For this simple GET example no additional parameter is required but the Redfish object's put and post method may take request header and body as parameters while patch method can take request body as parameter.
response = REDFISH_OBJ.get('/redfish/v1/systems/1')
Print the HTTP GET response, the response includes response status, response header and response body.
sys.stdout.write("%s\n" % response)
Response status:
200
Response header:
content-length 4135server HPE-iLO-Server/1.30connection keep-aliveetag W/"F7BDA039"link </redfish/v1/SchemaStore/en/ComputerSystem.json>; rel=describedbyallow GET, HEAD, POST, PATCHcache-control no-cachedate Mon, 14 Mar 2016 10:05:32 GMTx-frame-options sameoriginx_hp-chrp-service-version 1.0.3content-type application/json; charset=utf-8
Response body (formatted using Postman):
Logout of the current session.
REDFISH_OBJ.logout()