### Install python-ipmi using setup.py Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/introduction.md This command is used for manual installation after downloading and extracting the source distribution package. ```bash python setup.py install ``` -------------------------------- ### Setup IPMITOOL LAN Interface and Connection Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md Use this to set up the ipmitool interface for network connections. Ensure ipmitool is installed and accessible. The Target class is used to specify routing information for reaching specific IPMB addresses. ```python interface = pyipmi.interfaces.create_interface(interface='ipmitool', interface_type='lan') ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp('10.0.0.1', port=623) ipmi.session.set_auth_type_user('admin', 'admin') ipmi.target = pyipmi.Target(ipmb_address=0x82, routing=[(0x81,0x20,0),(0x20,0x82,7)]) ipmi.session.establish() ipmi.get_device_id() ``` -------------------------------- ### Setup IPMITOOL Serial Terminal Interface and Connection Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md Use this to set up the ipmitool interface for serial terminal connections. Ensure ipmitool is installed and accessible. The Target class is used to specify the IPMB address. ```python interface = pyipmi.interfaces.create_interface(interface='ipmitool', interface_type='serial-terminal') ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_serial('/dev/tty2', 115200) ipmi.target = pyipmi.Target(0xb2) ipmi.session.establish() ipmi.get_device_id() ``` -------------------------------- ### Setup RMCP Connection and Get SDR Repository Info Source: https://context7.com/kontron/python-ipmi/llms.txt Establishes an RMCP connection to an IPMI device and retrieves information about the SDR repository, including version, record count, and free space. Requires `pyipmi` and `pyipmi.interfaces` to be imported. ```python import pyipmi import pyipmi.interfaces # Setup connection interface = pyipmi.interfaces.create_interface('rmcp') ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp('10.0.0.1', 623) ipmi.session.set_auth_type_user('admin', 'admin') ipmi.target = pyipmi.Target(ipmb_address=0x20) ipmi.session.establish() # Get SDR repository info sdr_info = ipmi.get_sdr_repository_info() print("SDR Repository Info:") print(f" Version: {sdr_info.version}") print(f" Record Count: {sdr_info.record_count}") print(f" Free Space: {sdr_info.free_space} bytes") # Get SDR repository allocation info alloc_info = ipmi.get_sdr_repository_allocation_info() print("\nSDR Repository Allocation:") print(f" Number of units: {alloc_info.number_of_units}") print(f" Unit size: {alloc_info.unit_size} bytes") print(f" Free units: {alloc_info.free_units}") # Reserve SDR repository (required for some operations) reservation_id = ipmi.reserve_sdr_repository() print(f"\nReservation ID: {reservation_id}") # Get a specific SDR by record ID sdr_record = ipmi.get_repository_sdr(record_id=0) print(f"\nSDR Record: {sdr_record}") # Iterate through all SDR entries print("\nAll SDR Entries:") for sdr in ipmi.sdr_repository_entries(): print(f" ID: {sdr.id:#06x}, Type: {sdr.type:#04x}, Name: {getattr(sdr, 'device_id_string', 'N/A')}") # For full sensor records, show additional info if hasattr(sdr, 'sensor_type_code'): print(f" Sensor Type: {sdr.sensor_type_code:#04x}") if hasattr(sdr, 'entity_id'): print(f" Entity ID: {sdr.entity_id}") ipmi.session.close() ``` -------------------------------- ### Install python-ipmi using pip Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/introduction.md Use this command to install the library via pip. This is the recommended method, even for Anaconda users. ```bash pip install python-ipmi ``` -------------------------------- ### Connect and Get Boot Information Source: https://context7.com/kontron/python-ipmi/llms.txt Establishes an RMCP connection, retrieves current boot device, mode, and persistency settings. Requires valid connection details. ```python # Setup connection interface = pyipmi.interfaces.create_interface('rmcp') ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp('10.0.0.1', 623) ipmi.session.set_auth_type_user('admin', 'admin') ipmi.target = pyipmi.Target(ipmb_address=0x20) ipmi.session.establish() # Get current boot device boot_device = ipmi.get_boot_device() print(f"Current Boot Device: {boot_device}") # Get current boot mode (legacy or EFI) boot_mode = ipmi.get_boot_mode() print(f"Current Boot Mode: {boot_mode}") # Get boot persistency (applies to next boot only or permanent) persistent = ipmi.get_boot_persistency() print(f"Boot Persistent: {persistent}") # Available boot devices: # BootDevice.NO_OVERRIDE - No override # BootDevice.PXE - Network/PXE boot # BootDevice.DEFAULT_HDD - Default hard drive # BootDevice.DEFAULT_HDD_SAFE - Hard drive safe mode # BootDevice.DIAGNOSTIC - Diagnostic partition # BootDevice.CD - CD/DVD-ROM # BootDevice.BIOS - BIOS setup # BootDevice.REMOTE_USB - Remote USB # BootDevice.PRIMARY_REMOTE - Primary remote media # BootDevice.REMOTE_CD - Remote CD/DVD # BootDevice.REMOTE_HDD - Remote hard drive # BootDevice.PRIMARY_USB - Primary USB # Set boot options ipmi.set_boot_options( boot_device=BootDevice.PXE, boot_mode='efi', # 'legacy' or 'efi' boot_persistency=False # False = next boot only, True = permanent ) print("Boot options configured for PXE, EFI mode, next boot only") # Set to boot from hard drive permanently ipmi.set_boot_options( boot_device=BootDevice.DEFAULT_HDD, boot_mode='legacy', boot_persistency=True ) print("Boot options configured for HDD, legacy mode, persistent") ipmi.session.close() ``` -------------------------------- ### Import python-ipmi Library Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md Import the necessary modules from the python-ipmi library after installation. ```python import pyipmi import pyipmi.interfaces ``` -------------------------------- ### Connect via IPMI LAN Interface using ipmitool Source: https://github.com/kontron/python-ipmi/blob/master/README.rst Example demonstrating how to set up an IPMI connection using the 'lan' interface type with ipmitool backend. Requires specifying target, session details, authentication, and establishing the session. ```python import pyipmi import pyipmi.interfaces # Supported interface_types for ipmitool are: 'lan' , 'lanplus', and 'serial-terminal' interface = pyipmi.interfaces.create_interface('ipmitool', interface_type='lan') connection = pyipmi.create_connection(interface) connection.target = pyipmi.Target(0x82) connection.target.set_routing([(0x81,0x20,0),(0x20,0x82,7)]) connection.session.set_session_type_rmcp('10.0.0.1', port=623) connection.session.set_auth_type_user('admin', 'admin') connection.session.set_priv_level("ADMINISTRATOR") connection.session.establish() connection.get_device_id() ``` ```shell ipmitool -I lan -H 10.0.0.1 -p 623 -L "ADMINISTRATOR" -U "admin" -P "admin" -t 0x82 -b 0 -l 0 raw 0x06 0x01 ``` -------------------------------- ### Connect via IPMI Serial Interface using ipmitool Source: https://github.com/kontron/python-ipmi/blob/master/README.rst Example demonstrating how to set up an IPMI connection using the 'serial-terminal' interface type with ipmitool backend. Requires specifying target, serial port, baud rate, and establishing the session. ```python import pyipmi import pyipmi.interfaces interface = pyipmi.interfaces.create_interface('ipmitool', interface_type='serial-terminal') connection = pyipmi.create_connection(interface) connection.target = pyipmi.Target(0xb2) # set_session_type_serial(port, baudrate) connection.session.set_session_type_serial('/dev/tty2', 115200) connection.session.establish() connection.get_device_id() ``` ```shell ipmitool -I serial-terminal -D /dev/tty2:115200 -t 0xb2 -l 0 raw 0x06 0x01 ``` -------------------------------- ### Chassis Control Command Example Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/chassis_cmd.md Provides a mechanism for power control (up, down, cycle) and system reset. Use the predefined constants for options like power down, power up, or hard reset. ```python ipmi.chassis_control(option) ``` -------------------------------- ### Create Aardvark Interface and Get Device Info Source: https://context7.com/kontron/python-ipmi/llms.txt Demonstrates creating an Aardvark interface with a specific serial number and retrieving basic device information. No session is required for IPMB communication. ```python import pyipmi interface = pyipmi.interfaces.create_interface( 'aardvark', slave_address=0x20, serial_number='2237-523145' # Aardvark device serial ) ipmi = pyipmi.create_connection(interface) ipmi.target = pyipmi.Target(ipmb_address=0xb4) device_id = ipmi.get_device_id() print(f"Device ID: {device_id.device_id}") print(f"Device Revision: {device_id.revision}") print(f"Firmware Revision: {device_id.fw_revision}") print(f"IPMI Version: {device_id.ipmi_version}") print(f"Manufacturer ID: {device_id.manufacturer_id} (0x{device_id.manufacturer_id:04x})") print(f"Product ID: {device_id.product_id} (0x{device_id.product_id:04x})") print(f"Device Available: {device_id.available}") print(f"Provides SDRs: {device_id.provides_sdrs}") ``` -------------------------------- ### Send IPMI Command by Name Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md This example shows how to send an IPMI command using its predefined string name. The 'GetDeviceId' command is used here, and the returned object's type depends on the command issued. ```python ipmi.send_message_with_name('GetDeviceId') ``` -------------------------------- ### Create Legacy RMCP Interface with ipmitool Backend Source: https://context7.com/kontron/python-ipmi/llms.txt Utilizes the ipmitool command-line utility for RMCP communication, supporting 'lan', 'lanplus', and 'serial-terminal' interface types. This example demonstrates LAN communication with routing information. ```python import pyipmi import pyipmi.interfaces # Create ipmitool-based interface for LAN communication interface = pyipmi.interfaces.create_interface( interface='ipmitool', interface_type='lanplus' # Options: 'lan', 'lanplus', 'serial-terminal' ) # Create connection and configure session ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp('10.0.0.1', port=623) ipmi.session.set_auth_type_user('admin', 'admin') # Set target with bridging/routing information # Format: [(source_addr, dest_addr, channel), ...] ipmi.target = pyipmi.Target( ipmb_address=0x82, routing=[(0x81, 0x20, 0), (0x20, 0x82, 7)] ) # Establish session and execute commands ipmi.session.establish() device_id = ipmi.get_device_id() print(f"Device ID: {device_id}") ipmi.session.close() # Equivalent ipmitool command: # ipmitool -I lanplus -H 10.0.0.1 -p 623 -U "admin" -P "admin" -t 0x82 -b 0 -l 0 raw 0x06 0x01 ``` -------------------------------- ### Get Watchdog Timer Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/bmcWatchdog_cmd.md Retrieves the current settings and present countdown of the watchdog timer. This command is mandatory as per the IPMI standard. ```APIDOC ## Get Watchdog Timer Command ### Description This command retrieves the current settings and present countdown of the watchdog timer. ### Method GET (or equivalent API call) ### Endpoint /api/bmc/watchdog/get ### Parameters None ### Request Example ```python watchdog_timer = ipmi.get_watchdog_timer() ``` ### Response #### Success Response (200) Returns an object with the current watchdog timer settings and countdown. - **dont_log** (boolean) - Whether the timeout event is logged. - **is_running** (boolean) - Whether the timer is currently running. - **timer_use** (integer) - The purpose of the timer. - **pre_timeout_interrupt** (integer) - The type of interrupt before timeout. - **timeout_action** (integer) - The action taken upon timeout. - **pre_timeout_interval** (integer) - The interval in seconds before timeout. - **timer_use_expiration_flags** (integer) - Expiration flags related to timer use. - **initial_countdown** (integer) - The initial countdown value in seconds. - **present_countdown** (integer) - The current countdown value in seconds. #### Response Example ```json { "dont_log": false, "is_running": true, "timer_use": 3, "pre_timeout_interrupt": 2, "timeout_action": 1, "pre_timeout_interval": 60, "timer_use_expiration_flags": 1, "initial_countdown": 120, "present_countdown": 95 } ``` ``` -------------------------------- ### Get Channel Authentication Capabilities Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/ipmiMsgSupport_cmd.md Retrieves capability information about a specific IPMI channel. ```APIDOC ## get_channel_authentication_capabilities(channel, priv_lvl) ### Description This command is used to retrieve capability information about a particular channel. ### Parameters - **channel** (int) - Required - The channel number. - **priv_lvl** (int) - Required - The requested maximum privilege level. ### Request Example ```python ipmi.get_channel_authentication_capabilities(channel=0x0E, priv_lvl=1) ``` ``` -------------------------------- ### Get Device ID and Supported Functions Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/ipmDevGlobal_cmd.md Retrieves the device ID and checks for supported functions like 'sensor', 'sel', etc. Use this to understand the capabilities of the IPMI device. ```python device_id = ipmi.get_device_id() print("--- Printing Device ID ---") functions = ( ('SENSOR', 'Sensor Device', 11), ('SDR_REPOSITORY', 'SDR Repository Device', 3), ('SEL', 'SEL Device', 14), ('FRU_INVENTORY', 'FRU Inventory Device', 4), ('IPMB_EVENT_RECEIVER', 'IPMB Event Receiver', 5), ('IPMB_EVENT_GENERATOR', 'IPMB Event Generator', 4), ('BRIDGE', 'Bridge', 18), ('CHASSIS', 'Chassis Device', 10)) ChkBox=['[ ]','[X]'] print(''' Device ID: %(device_id)s Provides Device SDRs: %(provides_sdrs)s Device Revision: %(revision)s Device Available: %(available)d Firmware Revision: %(fw_revision)s IPMI Version: %(ipmi_version)s Manufacturer ID: %(manufacturer_id)d (0x%(manufacturer_id)04x) Product ID: %(product_id)d (0x%(product_id)04x) Aux Firmware Rev Info: %(aux)s Additional Device Support: '''[1:-1] % device_id.__dict__) for n, s, l in functions: if device_id.supports_function(n): print(' %s%s%s' % (s,l*' ',ChkBox[1])) else: print(' %s%s%s' % (s,l*' ',ChkBox[0])) ``` -------------------------------- ### Get Chassis Status Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/chassis_cmd.md Retrieves the high-level status of the system chassis and main power subsystem. ```APIDOC ## Get Chassis Status Command ### Description This command returns information regarding the high-level status of the system chassis and main power subsystem. ### Method GET ### Endpoint /chassis/status ### Parameters None ### Request Example ```python chassis_status = ipmi.get_chassis_status() ``` ### Response #### Success Response (200) - **restore_policy** (boolean) - Indicates if the power restore policy is enabled. - **control_fault** (boolean) - Indicates if there is a control fault. - **fault** (boolean) - Indicates if there is a general fault. - **interlock** (boolean) - Indicates if the chassis interlock is active. - **overload** (boolean) - Indicates if the system is overloaded. - **power_on** (boolean) - Indicates if the system is powered on. - **last_event** (integer) - The code for the last event. - **chassis_state** (string) - The current state of the chassis. #### Response Example ```json { "restore_policy": false, "control_fault": false, "fault": false, "interlock": false, "overload": false, "power_on": true, "last_event": 12, "chassis_state": "on" } ``` ``` -------------------------------- ### Get Channel Authentication Capabilities Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/ipmiMsgSupport_cmd.md Retrieves capability information for a specific channel. Pass the channel number and the requested maximum privilege level to this function. ```python ipmi.get_channel_authentication_capabilities(channel=0x0E,priv_lvl=1) ``` -------------------------------- ### Get Sensor Reading and Set Thresholds Source: https://context7.com/kontron/python-ipmi/llms.txt Retrieves the current reading and states for a specific sensor number, sets sensor thresholds (unr, ucr, unc, lnc, lcr, lnr), and rearms sensor events. Requires an established RMCP connection. ```python import pyipmi import pyipmi.interfaces # Setup connection interface = pyipmi.interfaces.create_interface('rmcp') ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp('10.0.0.1', 623) ipmi.session.set_auth_type_user('admin', 'admin') ipmi.target = pyipmi.Target(ipmb_address=0x20) ipmi.session.establish() # Get sensor reading by sensor number sensor_number = 0x01 reading, states = ipmi.get_sensor_reading(sensor_number, lun=0) if reading is not None: print(f"Sensor {sensor_number:#04x} Reading: {reading}") print(f"Sensor States: {states:#06x}" if states else "Sensor States: N/A") else: print(f"Sensor {sensor_number:#04x}: Initial update in progress") # Set sensor thresholds # unr = Upper Non-Recoverable # ucr = Upper Critical # unc = Upper Non-Critical # lnc = Lower Non-Critical # lcr = Lower Critical # lnr = Lower Non-Recoverable ipmi.set_sensor_thresholds( sensor_number=0x01, lun=0, unr=95, # Upper non-recoverable ucr=85, # Upper critical unc=75, # Upper non-critical lnc=10, # Lower non-critical lcr=5, # Lower critical lnr=0 # Lower non-recoverable ) print("Sensor thresholds updated") # Rearm sensor events ipmi.rearm_sensor_events(sensor_number=0x01) print("Sensor events rearmed") # Get device SDR list (for sensors that provide their own SDRs) device_sdrs = ipmi.get_device_sdr_list() print(f"\nDevice SDR count: {len(device_sdrs)}") # Iterate through device SDR entries for sdr in ipmi.device_sdr_entries(): if hasattr(sdr, 'device_id_string'): print(f" {sdr.device_id_string}") ipmi.session.close() ``` -------------------------------- ### Configure Boot Options with Python IPMI Source: https://context7.com/kontron/python-ipmi/llms.txt This snippet demonstrates how to configure system boot options, including the boot device, mode, and persistence. It requires the `pyipmi.chassis.BootDevice` enum. ```python import pyipmi import pyipmi.interfaces from pyipmi.chassis import BootDevice ``` -------------------------------- ### Reset Watchdog Timer Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/bmcWatchdog_cmd.md Use this command to start or restart the Watchdog Timer with a previously specified countdown value. ```python ipmi.reset_watchdog_timer() ``` -------------------------------- ### Configure Library Logging Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md Sets up the Python logging module to record library events to a file named ipmi_debug.log. ```python import logging logging.basicConfig(filename='ipmi_debug.log', filemode='w', level=logging.DEBUG) ``` -------------------------------- ### System Reset Commands Source: https://context7.com/kontron/python-ipmi/llms.txt Initiate cold or warm resets on the target system. Note that connections may be lost following these commands. ```python ipmi.cold_reset() print("Cold reset initiated") # Warm Reset - Partial device reset # Resets communication interfaces only # Preserves current configurations (interrupts, thresholds, etc.) # Does not initiate Self Test ipmi.warm_reset() print("Warm reset initiated") ``` -------------------------------- ### Get Device ID Command Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/ipmDevGlobal_cmd.md Retrieves the Intelligent Devices’s HW revision, FW/SW revision, and information regarding additional logical device functionality. ```APIDOC ## Get Device ID Command ### Description Retrieves the Intelligent Devices’s HW revision, FW/SW revision, and information regarding additional logical device functionality. ### Method GET (or equivalent API call for retrieving device information) ### Endpoint Not explicitly defined, assumed to be part of a device management API. ### Parameters None ### Request Example ```python device_id = ipmi.get_device_id() ``` ### Response #### Success Response (200) - **device_id** (object) - The device ID object containing detailed information. - **device_id** (int) - The device ID. - **provides_sdrs** (bool) - Indicates if the device provides SDRs. - **revision** (int) - The device revision. - **available** (int) - Device availability status. - **fw_revision** (object) - Firmware revision details. - **major** (int) - **minor** (int) - **ipmi_version** (object) - IPMI version details. - **major** (int) - **minor** (int) - **supported_functions** (list) - List of supported functions. - **manufacturer_id** (int) - Manufacturer ID. - **product_id** (int) - Product ID. - **aux** (object) - Auxiliary firmware revision information. #### Response Example ```python # Example output structure, actual values will vary # Assuming device_id is an object with attributes like: # device_id.device_id, device_id.provides_sdrs, etc. # The print statement in the provided text demonstrates how to access these. ``` ### Additional Information The returned object has a method `supports_function(func_name)` which returns 'True' if the given function is supported by the Target, otherwise 'False'. Supported functions include: ‘sensor’, ‘sdr_repository’, ‘sel’, ‘fru_inventory’, ‘ipmb_event_receiver’, ‘ipmb_event_generator’, ‘bridge’, ‘chassis’. ``` -------------------------------- ### IPMI and PICMG Command Reference Source: https://github.com/kontron/python-ipmi/blob/master/docs/commands.rst A comprehensive list of supported IPMI and PICMG commands including session management, FRU data, SDR/SEL repositories, and PICMG specific operations. ```APIDOC ## IPMI Command List ### Description This table outlines the available IPMI commands categorized by their NetFn and Command codes. ### Commands | NetFn | Cmd | Name | |---|---|---| | 0x6 | 0x3c | CloseSession | | 0x6 | 0x52 | MasterWriteRead | | 0xa | 0x10 | GetFruInventoryAreaInfo | | 0xa | 0x11 | ReadFruData | | 0xa | 0x12 | WriteFruData | | 0xa | 0x20 | GetSdrRepositoryInfo | | 0xa | 0x21 | GetSdrRepositoryAllocationInfo | | 0xa | 0x22 | ReserveSdrRepository | | 0xa | 0x23 | GetSdr | | 0xa | 0x24 | AddSdr | | 0xa | 0x25 | PartialAddSdr | | 0xa | 0x26 | DeleteSdr | | 0xa | 0x27 | ClearSdrRepository | | 0xa | 0x2c | RunInitializationAgent | | 0xa | 0x40 | GetSelInfo | | 0xa | 0x41 | GetSelAllocationInfo | | 0xa | 0x42 | ReserveSel | | 0xa | 0x43 | GetSelEntry | | 0xa | 0x44 | AddSelEntry | | 0xa | 0x46 | DeleteSelEntry | | 0xa | 0x47 | ClearSel | | 0xa | 0x48 | GetSelTime | | 0xa | 0x49 | SetSelTime | | 0xc | 0x1 | SetLanConfigurationParameters | | 0xc | 0x2 | GetLanConfigurationParameters | ## PICMG Command List ### Description This table outlines the available PICMG commands. ### Commands | NetFn | Cmd | Name | |---|---|---| | 0x2c | 0x0 | GetPicmgProperties | | 0x2c | 0x1 | GetAddressInfo | | 0x2c | 0x2 | GetShelfAddressInfo | | 0x2c | 0x4 | FruControl | | 0x2c | 0x5 | GetFruLedProperties | | 0x2c | 0x6 | GetFruLedColorCapabilities | | 0x2c | 0x7 | SetFruLedState | | 0x2c | 0x8 | GetFruLedState | | 0x2c | 0xa | SetFruActivationPolicy | | 0x2c | 0xb | GetFruActivationPolicy | | 0x2c | 0xc | SetFruActivation | | 0x2c | 0xd | GetDeviceLocatorRecordId | | 0x2c | 0xe | SetPortState | ``` -------------------------------- ### Create Native RMCP Interface and Session Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md Establishes a native RMCP interface and connects to an IPMI device. Requires host, port, username, and password for authentication. This snippet also retrieves and prints device information. ```python interface = pyipmi.interfaces.create_interface(interface='rmcp', slave_address=0x81, host_target_address=0x20, keep_alive_interval=1) ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp(host='10.0.114.199', port=623) ipmi.session.set_auth_type_user(username='admin', password='admin') ipmi.target = pyipmi.Target(ipmb_address=0x20) ipmi.session.establish() device_id = ipmi.get_device_id() # Below code used only to print out the device ID information print(''' Device ID: %(device_id)s Device Revision: %(revision)s Firmware Revision: %(fw_revision)s IPMI Version: %(ipmi_version)s Manufacturer ID: %(manufacturer_id)d (0x%(manufacturer_id)04x) Product ID: %(product_id)d (0x%(product_id)04x) Device Available: %(available)d Provides SDRs: %(provides_sdrs)d Additional Device Support: '''[1:-1] % device_id.__dict__) functions = ( ('SENSOR', 'Sensor Device'), ('SDR_REPOSITORY', 'SDR Repository Device'), ('SEL', 'SEL Device'), ('FRU_INVENTORY', 'FRU Inventory Device'), ('IPMB_EVENT_RECEIVER', 'IPMB Event Receiver'), ('IPMB_EVENT_GENERATOR', 'IPMB Event Generator'), ('BRIDGE', 'Bridge'), ('CHASSIS', 'Chassis Device') ) for n, s in functions: if device_id.supports_function(n): print(' %s' % s) if device_id.aux is not None: print('Aux Firmware Rev Info: [%s]' % ( ' '.join('0x%02x' % d for d in device_id.aux))) ``` -------------------------------- ### Get Chassis Status Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/chassis_cmd.md Retrieves the high-level status of the system chassis and main power subsystem. The returned object contains attributes like restore policy, control fault, and power status. ```python chassis_status=ipmi.get_chassis_status() ``` -------------------------------- ### Get Device ID Command Source: https://context7.com/kontron/python-ipmi/llms.txt Retrieves the BMC's hardware revision, firmware revision, and supported device functions using the high-level API. Checks for support of various IPMI functions. ```python import pyipmi import pyipmi.interfaces interface = pyipmi.interfaces.create_interface('rmcp') ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp('10.0.0.1', 623) ipmi.session.set_auth_type_user('admin', 'admin') ipmi.target = pyipmi.Target(ipmb_address=0x20) ipmi.session.establish() device_id = ipmi.get_device_id() print(f"Device ID: {device_id.device_id}") print(f"Provides Device SDRs: {device_id.provides_sdrs}") print(f"Device Revision: {device_id.revision}") print(f"Device Available: {device_id.available}") print(f"Firmware Revision: {device_id.fw_revision}") print(f"IPMI Version: {device_id.ipmi_version}") print(f"Manufacturer ID: {device_id.manufacturer_id} (0x{device_id.manufacturer_id:04x})") print(f"Product ID: {device_id.product_id} (0x{device_id.product_id:04x})") print(f"Aux Firmware Rev: {device_id.aux}") functions = [ ('SENSOR', 'Sensor Device'), ('SDR_REPOSITORY', 'SDR Repository Device'), ('SEL', 'SEL Device'), ('FRU_INVENTORY', 'FRU Inventory Device'), ('IPMB_EVENT_RECEIVER', 'IPMB Event Receiver'), ('IPMB_EVENT_GENERATOR', 'IPMB Event Generator'), ('BRIDGE', 'Bridge'), ('CHASSIS', 'Chassis Device') ] print("\nSupported Functions:") for func_name, func_desc in functions: supported = device_id.supports_function(func_name) status = "[X]" if supported else "[ ]" print(f" {status} {func_desc}") ipmi.session.close() ``` -------------------------------- ### Set Watchdog Timer Configuration Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/bmcWatchdog_cmd.md Initialize and configure the Watchdog Timer, or stop it by setting a timeout value of '0'. ```python ipmi.set_watchdog_timer(watchdog_timer) ``` -------------------------------- ### IPMITOOL Command for LAN Connection Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md This is the equivalent ipmitool command-line execution for the Python script above, demonstrating direct interaction with the IPMI interface. ```shell ipmitool -I lan -H 10.0.0.1 -p 623 -U "admin" -P "admin" -t 0x82 -b 0 -l 0 raw 0x06 0x01 ``` -------------------------------- ### Get Watchdog Timer Status Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/bmcWatchdog_cmd.md Retrieve the current settings and countdown of the watchdog timer. The returned object contains attributes like 'dont_log', 'is_running', 'timer_use', 'pre_timeout_interrupt', 'timeout_action', 'pre_timeout_interval', 'timer_use_expiration_flags', 'initial_countdown', and 'present_countdown'. ```python watchdog_timer=ipmi.get_watchdog_timer() print("--- Printing Watchdog Timer ---") timer_use_const=['BIOS FRB2','BIOS/POST','OS Load','SMS/OS','OEM'] pretime_intr_const=['None','SMI','NMI','Msg intr'] timeout_act_const=['No action','Hard Reset','Power Down','Power Cycle'] print(""" Don't log: {0[dont_log]:} Timer is running: {0[is_running]:} Pre-timout interval: {0[pre_timeout_interval]:d} Initial countdown value: {0[initial_countdown]:d} Present countdown value: {0[present_countdown]:d} """[1:-1].format(wd_timer.__dict__),end='') print(" Timer use: ", timer_use_const[watchdog_timer.__dict__['timer_use']-1]) print(" Timer use expiration flag: ", timer_use_const[watchdog_timer.__dict__['timer_use_expiration_flags']-1]) print(" Pre-timeout interrupt: ", pretime_intr_const[watchdog_timer.__dict__['pre_timeout_interval']]) print(" Time out action: ", timeout_act_const[watchdog_timer.__dict__['timeout_action']]) ``` -------------------------------- ### Use Context Manager for IPMI Connection Handling Source: https://context7.com/kontron/python-ipmi/llms.txt Leverages Python's context manager for automatic session establishment and cleanup. This ensures the IPMI session is properly opened and closed, simplifying resource management. ```python import pyipmi import pyipmi.interfaces # Configure interface and session intf = pyipmi.interfaces.create_interface( 'rmcp', slave_address=0x81, host_target_address=0x20, keep_alive_interval=0 ) sess = pyipmi.Session() sess.set_session_type_rmcp('10.0.114.116', 623) sess.set_auth_type_user('admin', 'admin') sess.set_priv_level("ADMINISTRATOR") target = pyipmi.Target(ipmb_address=0x20) # Use context manager for automatic open/close with pyipmi.Ipmi(interface=intf, session=sess, target=target) as ipmi: device_id = ipmi.get_device_id() print(f"Device ID: {device_id.device_id}") print(f"Manufacturer: {device_id.manufacturer_id:#06x}") print(f"Product: {device_id.product_id:#06x}") # Check auxiliary firmware revision info if device_id.aux is not None: aux_str = ' '.join(f'0x{d:02x}' for d in device_id.aux) print(f"Aux Firmware Rev: [{aux_str}]") # Session automatically closed when exiting context ``` -------------------------------- ### Specific Chassis Control Methods Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/chassis_cmd.md Convenience methods for individual chassis control actions. These methods abstract the integer options for common power and reset operations. ```python ipmi.chassis_control_power_down() ``` ```python ipmi.chassis_control_power_up() ``` ```python ipmi.chassis_control_power_cycle() ``` ```python ipmi.chassis_control_hard_reset() ``` ```python ipmi.chassis_control_diagnostic_interrupt() ``` ```python ipmi.chassis_control_soft_shutdown() ``` -------------------------------- ### IPMB Interface with Aardvark Tool Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md This code demonstrates setting up an IPMB interface using the Aardvark tool. It requires specifying the Aardvark slave address and serial number. The output includes detailed device information and supported functions. ```python interface = pyipmi.interfaces.create_interface('aardvark', slave_address=0x20, serial_number='2237-523145') ipmi = pyipmi.create_connection(interface) ipmi.target = pyipmi.Target(ipmb_address=0xb4) device_id = ipmi.get_device_id() # Below code used only to print out the device ID information print(''' Device ID: %(device_id)s Device Revision: %(revision)s Firmware Revision: %(fw_revision)s IPMI Version: %(ipmi_version)s Manufacturer ID: %(manufacturer_id)d (0x%(manufacturer_id)04x) Product ID: %(product_id)d (0x%(product_id)04x) Device Available: %(available)d Provides SDRs: %(provides_sdrs)d Additional Device Support: '''[1:-1] % device_id.__dict__) functions = ( ('SENSOR', 'Sensor Device'), ('SDR_REPOSITORY', 'SDR Repository Device'), ('SEL', 'SEL Device'), ('FRU_INVENTORY', 'FRU Inventory Device'), ('IPMB_EVENT_RECEIVER', 'IPMB Event Receiver'), ('IPMB_EVENT_GENERATOR', 'IPMB Event Generator'), ('BRIDGE', 'Bridge'), ('CHASSIS', 'Chassis Device') ) for n, s in functions: if device_id.supports_function(n): print(' %s' % s) if device_id.aux is not None: print('Aux Firmware Rev Info: [%s]' % ( ' '.join('0x%02x' % d for d in device_id.aux))) ``` -------------------------------- ### IPMI Commands Source: https://github.com/kontron/python-ipmi/blob/master/docs/commands.rst This section lists various IPMI commands available in the /kontron/python-ipmi project. ```APIDOC ## GetPortState ### Description Retrieves the state of a specific port. ### Method GET ### Endpoint /kontron/python-ipmi/portstate ## GetPowerLevel ### Description Retrieves the current power level. ### Method GET ### Endpoint /kontron/python-ipmi/powerlevel ## GetFanSpeedProperties ### Description Retrieves the properties of the fan speed. ### Method GET ### Endpoint /kontron/python-ipmi/fanspeedproperties ## SetFanLevel ### Description Sets the fan level. ### Method POST ### Endpoint /kontron/python-ipmi/falevel ### Request Body - **level** (integer) - Required - The desired fan level. ## GetFanLevel ### Description Retrieves the current fan level. ### Method GET ### Endpoint /kontron/python-ipmi/falevel ## GetFruControlCapabilities ### Description Retrieves the capabilities for Field Replaceable Unit (FRU) control. ### Method GET ### Endpoint /kontron/python-ipmi/frucontrolcapabilities ## GetLocationInformation ### Description Retrieves location information. ### Method GET ### Endpoint /kontron/python-ipmi/locationinformation ## SendPowerChannelControl ### Description Sends a command to control a power channel. ### Method POST ### Endpoint /kontron/python-ipmi/powerchannelcontrol ### Request Body - **channel** (integer) - Required - The power channel to control. - **command** (string) - Required - The command to send (e.g., 'on', 'off', 'reset'). ## GetPowerChannelStatus ### Description Retrieves the status of a power channel. ### Method GET ### Endpoint /kontron/python-ipmi/powerchannelstatus ### Query Parameters - **channel** (integer) - Required - The power channel to query. ## SendPmHeartbeat ### Description Sends a Platform Management (PM) heartbeat signal. ### Method POST ### Endpoint /kontron/python-ipmi/pmheartbeat ## GetTelcoAlarmCapability ### Description Retrieves the Telco alarm capability. ### Method GET ### Endpoint /kontron/python-ipmi/telcoalarmcapability ## GetTargetUpgradeCapabilities ### Description Retrieves the capabilities for target firmware upgrades. ### Method GET ### Endpoint /kontron/python-ipmi/targetupgradecapabilities ## GetComponentProperties ### Description Retrieves the properties of a specific component. ### Method GET ### Endpoint /kontron/python-ipmi/componentproperties ### Query Parameters - **component_id** (string) - Required - The ID of the component. ## AbortFirmwareUpgrade ### Description Aborts an ongoing firmware upgrade process. ### Method POST ### Endpoint /kontron/python-ipmi/abortfirmwareupgrade ## InitiateUpgradeAction ### Description Initiates a firmware upgrade action. ### Method POST ### Endpoint /kontron/python-ipmi/initiateupgradeaction ### Request Body - **action** (string) - Required - The upgrade action to initiate. ## UploadFirmwareBlock ### Description Uploads a block of firmware data. ### Method POST ### Endpoint /kontron/python-ipmi/uploadfirmwareblock ### Request Body - **block_data** (string) - Required - The firmware data block. - **offset** (integer) - Required - The offset for the data block. ## FinishFirmwareUpload ### Description Completes the firmware upload process. ### Method POST ### Endpoint /kontron/python-ipmi/finishfirmwareupload ## GetUpgradeStatus ### Description Retrieves the status of the current firmware upgrade. ### Method GET ### Endpoint /kontron/python-ipmi/upgradestatus ## ActivateFirmware ### Description Activates the newly uploaded firmware. ### Method POST ### Endpoint /kontron/python-ipmi/activatefirmware ## QuerySelftestResults ### Description Queries the results of the system's self-test. ### Method GET ### Endpoint /kontron/python-ipmi/selftestresults ## QueryRollbackStatus ### Description Queries the status of firmware rollback. ### Method GET ### Endpoint /kontron/python-ipmi/rollbackstatus ## InitiateManualRollback ### Description Initiates a manual firmware rollback. ### Method POST ### Endpoint /kontron/python-ipmi/manualrollback ## SetSignalingClass ### Description Sets the signaling class for communication. ### Method POST ### Endpoint /kontron/python-ipmi/signalingclass ### Request Body - **class** (string) - Required - The signaling class to set. ## GetSignalingClass ### Description Retrieves the current signaling class. ### Method GET ### Endpoint /kontron/python-ipmi/signalingclass ``` -------------------------------- ### Establish Session Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/ipmiMsgSupport_cmd.md High-level API function to establish a session between the Slave and the Target using multiple IPMI commands. ```APIDOC ## Establish Session ### Description Creates and activates a session of the ipmi.session instance with the given authentication and privilege level. It performs a sequence of IPMI commands including ping, Get Channel Authentication Capabilities, Get Session Challenge, Activate Session, and Set Session Privilege Level. ### Request Example ```python ipmi.session.establsih() ``` ``` -------------------------------- ### Create Native RMCP Interface Connection Source: https://context7.com/kontron/python-ipmi/llms.txt Establishes a direct UDP communication with a BMC using the native RMCP interface. Requires specifying slave and host target addresses, and optionally a keep-alive interval. ```python import pyipmi import pyipmi.interfaces # Create native RMCP interface with configuration interface = pyipmi.interfaces.create_interface( interface='rmcp', slave_address=0x81, host_target_address=0x20, keep_alive_interval=1 # Send keep-alive every 1 second ) # Create connection and configure session ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp(host='10.0.114.199', port=623) ipmi.session.set_auth_type_user(username='admin', password='admin') # Set the target BMC address ipmi.target = pyipmi.Target(ipmb_address=0x20) # Establish session and communicate ipmi.session.establish() device_id = ipmi.get_device_id() print(f"Device ID: {device_id.device_id}") print(f"Firmware Revision: {device_id.fw_revision}") print(f"IPMI Version: {device_id.ipmi_version}") print(f"Manufacturer ID: {device_id.manufacturer_id}") print(f"Product ID: {device_id.product_id}") # Check supported functions if device_id.supports_function('SENSOR'): print("Sensor Device: Supported") if device_id.supports_function('SDR_REPOSITORY'): print("SDR Repository Device: Supported") if device_id.supports_function('SEL'): print("SEL Device: Supported") if device_id.supports_function('FRU_INVENTORY'): print("FRU Inventory Device: Supported") # Close the session when done ipmi.session.close() ``` -------------------------------- ### IPMITOOL Command for Serial Terminal Connection Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/quick_start.md This is the equivalent ipmitool command-line execution for the Python script above, demonstrating direct interaction with the IPMI serial terminal interface. ```shell ipmitool -I serial-terminal -D /dev/tty2:115200 -t 0xb2 -l 0 raw 0x06 0x01 ``` -------------------------------- ### Send IPMI Commands by Name Source: https://context7.com/kontron/python-ipmi/llms.txt Sends IPMI commands using predefined command names for simplified message handling. Supports commands with and without arguments. ```python import pyipmi import pyipmi.interfaces interface = pyipmi.interfaces.create_interface('rmcp') ipmi = pyipmi.create_connection(interface) ipmi.session.set_session_type_rmcp('10.0.0.1', 623) ipmi.session.set_auth_type_user('admin', 'admin') ipmi.target = pyipmi.Target(ipmb_address=0x20) ipmi.session.establish() device_id_rsp = ipmi.send_message_with_name('GetDeviceId') print(f"Raw Device ID response: {device_id_rsp}") ipmi.send_message_with_name('ColdReset') # Perform cold reset ipmi.send_message_with_name('WarmReset') # Perform warm reset rsp = ipmi.send_message_with_name('GetFruInventoryAreaInfo', fru_id=0) print(f"FRU area size: {rsp.area_size}") rsp = ipmi.send_message_with_name('ReadFruData', fru_id=0, offset=0, count=32) print(f"FRU data: {rsp.data}") ipmi.session.close() ``` -------------------------------- ### Establish IPMI Session Source: https://github.com/kontron/python-ipmi/blob/master/docs/source/ipmiMsgSupport_cmd.md Establishes a session with the target using multiple IPMI commands. This high-level API function is used to create and activate a session with the given authentication and privilege level. ```python ipmi.session.establsih() ```