{"id":7564,"library":"pyghmi","title":"Pyghmi: Python General Hardware Management Initiative","description":"Pyghmi is a pure Python implementation of the Intelligent Platform Management Interface (IPMI) protocol, also supporting other hardware management initiatives. It enables programmatic control over server hardware, including power management, sensor monitoring, and console redirection (SOL). The library is actively maintained as part of OpenStack projects, with the current version 1.6.15 released on April 10, 2026, indicating a regular release cadence.","status":"active","version":"1.6.15","language":"en","source_language":"en","source_url":"https://opendev.org/x/pyghmi/","tags":["IPMI","hardware management","OpenStack","remote control","server management","BMC"],"install":[{"cmd":"pip install pyghmi","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for secure communication within IPMI (e.g., encryption, hashing).","package":"cryptography"},{"reason":"Provides extensions to the standard datetime module, potentially for timestamp handling in IPMI events.","package":"python-dateutil"},{"reason":"Python 2 and 3 compatibility utilities, indicating broader Python version support.","package":"six"},{"reason":"OpenStack-specific packaging and build requirements, primarily a build-time dependency.","package":"pbr","optional":true}],"imports":[{"note":"Directly importing `command` from `pyghmi.ipmi` is the standard way to access IPMI command functionality.","wrong":"import pyghmi.ipmi.command","symbol":"command","correct":"from pyghmi.ipmi import command"},{"note":"`bmc` related functionalities are typically found within the `pyghmi.ipmi` submodule.","wrong":"from pyghmi import bmc","symbol":"bmc","correct":"from pyghmi.ipmi import bmc"}],"quickstart":{"code":"import os\nfrom pyghmi.ipmi import command\n\n# Environment variables for BMC connection\nBMC_IP = os.environ.get('PYGHMI_BMC_IP', '192.168.1.100')\nBMC_USER = os.environ.get('PYGHMI_BMC_USER', 'admin')\nBMC_PASS = os.environ.get('PYGHMI_BMC_PASSWORD', 'password')\n\ntry:\n    # Establish an IPMI command session\n    # The `command.Command` object automatically manages session lifecycle.\n    ipmi_cmd = command.Command(\n        bmc=BMC_IP,\n        userid=BMC_USER,\n        password=BMC_PASS\n    )\n\n    print(f\"Connected to BMC at {BMC_IP}...\")\n\n    # Get power state\n    power_state = ipmi_cmd.get_power_state()\n    print(f\"Power State: {power_state['powerstate']}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure PYGHMI_BMC_IP, PYGHMI_BMC_USER, and PYGHMI_BMC_PASSWORD environment variables are set correctly.\")\n    print(\"Also verify network connectivity to the BMC and correct IPMI port (default 623).\")","lang":"python","description":"This quickstart demonstrates how to establish a connection to an IPMI BMC and retrieve its current power state using `pyghmi`. It relies on environment variables for BMC IP address, username, and password for secure configuration. The `command.Command` object manages the IPMI session lifecycle automatically."},"warnings":[{"fix":"To maintain an active session for long-running scripts or applications, explicitly call `ipmi_cmd.eventloop()` in a separate thread after creating the `Command` object. This method is responsible for housekeeping and keeping the session alive.","message":"IPMI sessions can time out if idle for too long (e.g., 30 seconds), leading to 'Session is logged out' errors or deadlocks on subsequent commands.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use the `pyghmi` package name and its corresponding import paths (e.g., `from pyghmi.ipmi import command`). Ensure your `pip install` command specifies `pyghmi`.","message":"The library was originally named 'ipmi' and later renamed to 'pyghmi'. Attempting to import or use older 'ipmi' references will result in `ModuleNotFoundError` or similar issues.","severity":"breaking","affected_versions":"Before 1.0.0 (historical)"},{"fix":"Double-check the BMC IP address, username, and password. Verify network connectivity to the BMC on UDP port 623 (default IPMI port). Ensure the BMC firmware supports IPMI v2.0/RMCP+ if that is the desired protocol version.","message":"When trying to establish an IPMI v2 / RMCP+ session, errors can occur due to network issues, incorrect credentials, or unsupported IPMI versions/configurations on the BMC itself.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Implement a background thread to run `ipmi_cmd.eventloop()` to prevent session timeouts. For example: `import threading; house_keeper_thread = threading.Thread(target=ipmi_cmd.eventloop, daemon=True); house_keeper_thread.start()`","cause":"The IPMI session was idle for too long and the BMC automatically terminated it.","error":"Error: Session is logged out"},{"fix":"Ensure `pyghmi` is correctly installed via `pip install pyghmi`. Verify the import statement is `from pyghmi.ipmi import ...`.","cause":"The `pyghmi` package is either not installed, or there's a typo in the import statement.","error":"No module named 'pyghmi.ipmi'"},{"fix":"Verify all connection parameters (IP, user, pass). Check firewall rules on both client and BMC. Use `ipmitool` from the command line to confirm basic connectivity if possible (e.g., `ipmitool -H <bmc_ip> -U <user> -P <pass> chassis power status`).","cause":"Common causes include incorrect BMC IP, username, password, network firewall blocking UDP port 623, or the BMC not supporting IPMI v2.0/RMCP+.","error":"Unable to establish IPMI v2 / RMCP+ session"}]}