Redfish Python Library

3.3.5 · active · verified Wed Apr 15

The Redfish Python Library, developed by the DMTF, is a reference implementation enabling Python developers to communicate with Redfish-conformant APIs. It simplifies interactions by performing basic HTTP operations (GET, POST, PUT, PATCH, DELETE) on Redfish services. The library is actively maintained, currently at version 3.3.5, with new releases typically occurring every few months.

Warnings

Install

Imports

Quickstart

This quickstart initializes a Redfish client, attempts to connect to the Redfish Service Root, and then fetches details about the first system if available. It demonstrates basic client creation, GET requests, and proper session logout. Credentials should be provided via environment variables for production use.

import redfish
import os

# Replace with your Redfish service details or use environment variables
LOGIN_HOST = os.environ.get('REDFISH_HOST', 'https://192.168.1.100')
LOGIN_ACCOUNT = os.environ.get('REDFISH_USERNAME', 'admin')
LOGIN_PASSWORD = os.environ.get('REDFISH_PASSWORD', 'password')

try:
    # Create a Redfish object
    REDFISH_OBJ = redfish.redfish_client(
        base_url=LOGIN_HOST,
        username=LOGIN_ACCOUNT,
        password=LOGIN_PASSWORD,
        default_prefix='/redfish/v1/'
    )

    # The client automatically logs in upon creation by default.
    # You can explicitly call login() if check_connectivity=False was used during client creation.
    # REDFISH_OBJ.login()

    # Perform a GET operation on the Service Root
    response = REDFISH_OBJ.get('/redfish/v1/')
    if response.status == 200:
        print("Successfully connected to Redfish Service Root:")
        print(response.dict)
    else:
        print(f"Failed to connect to Redfish Service Root: {response.status} - {response.text}")

    # Example: Get system information
    systems_uri = response.dict.get('Systems', {}).get('@odata.id')
    if systems_uri:
        systems_response = REDFISH_OBJ.get(systems_uri)
        if systems_response.status == 200:
            print("\nSystems information:")
            # Print the first system's summary if available
            if systems_response.dict and 'Members' in systems_response.dict and len(systems_response.dict['Members']) > 0:
                first_system_uri = systems_response.dict['Members'][0].get('@odata.id')
                if first_system_uri:
                    first_system_response = REDFISH_OBJ.get(first_system_uri)
                    if first_system_response.status == 200:
                        print(first_system_response.dict)
                    else:
                        print(f"Failed to get first system details: {first_system_response.status}")
            else:
                print("No systems found.")
        else:
            print(f"Failed to get systems: {systems_response.status}")
    else:
        print("Systems collection URI not found in Service Root.")

except redfish.rest.v1.redfish_exception.ServerDownOrUnreachableError as e:
    print(f"Error: Redfish service is down or unreachable: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")
finally:
    # Ensure to log out the session
    if 'REDFISH_OBJ' in locals() and REDFISH_OBJ:
        try:
            REDFISH_OBJ.logout()
            print("\nLogged out successfully.")
        except Exception as e:
            print(f"Error during logout: {e}")

view raw JSON →