-
Notifications
You must be signed in to change notification settings - Fork 180
Quick Start RMC
This is a basic detailed breakdown of quickstart_rmc.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 logger needs to be created to be able to track error codes.
LOGGERFILE = "RedfishApiExamples.log"
LOGGERFORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOGGER = redfish_logger(LOGGERFILE, LOGGERFORMAT, logging.ERROR)
LOGGER.info("Redfish API examples")
An RMC object instance is created by calling the RmcApp method of the imported redfish library. The RmcApp method returns an instance of the RMC client and takes optional arguments.
RMCOBJ = RmcApp([])
Next you will need to declare a cache directory and set for it for the RMC object.
config_dir = r'C:\DATA\redfish'
RMCOBJ.config.set_cachedir(os.path.join(config_dir, 'cache'))
cachedir = RMCOBJ.config.get_cachedir()
Next the RMC object's login method is called to initiate a redfish session. The parameters for the login method are user name, password and the base url.
RMCOBJ.login(username=login_account, password=login_password, \
base_url=login_host)
Please remember to call logout method once the session is completed.
After creating a RMC object as mentioned above in Create a RMC Object section followed by a login session.
Next the RMC object's get method is called with the system type ('ComputerSystem.') as the parameter.
RMCOBJ.select(['ComputerSystem.'])
Next you will do a GET and no additional parameter is required but the RMC object's put and post method may take request header and body as parameters while patch method can take request body as parameter.
response = RMCOBJ.get()
Print the JSON GET response, the response includes response status, response header and response body.
for item in response:
sys.stdout.write(json.dumps(item, indent=2, cls=JSONEncoder))
sys.stdout.write('\n')
Logout of the current session.
RMCOBJ.logout()