DMTF/python-redfish-library

Example using ContextManager is helpful

glimchb opened this issue · 2 comments

It will be very helpful to give this example how to use redfish with ContextManager :

with  redfish.redfish_client('https://192.168.1.100', 'admin', 'password') as REDFISH_OBJ:
    response = REDFISH_OBJ.get("/redfish/v1/systems/1")
    print response.text

It will save login and with suto-logout in case of error... No need in additional exception handling with finally

I never looked into this before and realized the library had implemented exit on the client object to perform this functionality; looks useful!

__enter__ is also implemented, so login can be skipped as well
see https://github.com/DMTF/python-redfish-library/blob/master/src/redfish/rest/v1.py#L494