1291ae830SBrad Bishop#!/usr/bin/env python 240a360c2SBrad Bishop 340a360c2SBrad Bishopimport dbus 440a360c2SBrad Bishop 540a360c2SBrad Bishopdbus_objects = { 6*75fe8cc4SPatrick Williams "power": { 7*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.control.Power", 8*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/control/power0", 9*75fe8cc4SPatrick Williams "interface_name": "org.openbmc.control.Power", 1040a360c2SBrad Bishop }, 11*75fe8cc4SPatrick Williams "occstatus0": { 12*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.Sensors", 13*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/sensors/host/cpu0/OccStatus", 14*75fe8cc4SPatrick Williams "interface_name": "org.openbmc.SensorValue", 1540a360c2SBrad Bishop }, 16*75fe8cc4SPatrick Williams "occstatus1": { 17*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.Sensors", 18*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/sensors/host/cpu1/OccStatus", 19*75fe8cc4SPatrick Williams "interface_name": "org.openbmc.SensorValue", 2040a360c2SBrad Bishop }, 21*75fe8cc4SPatrick Williams "bootprogress": { 22*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.Sensors", 23*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/sensors/host/BootProgress", 24*75fe8cc4SPatrick Williams "interface_name": "org.openbmc.SensorValue", 2540a360c2SBrad Bishop }, 26*75fe8cc4SPatrick Williams "host": { 27*75fe8cc4SPatrick Williams "bus_name": "xyz.openbmc_project.State.Host", 28*75fe8cc4SPatrick Williams "object_name": "/xyz/openbmc_project/state/host0", 29*75fe8cc4SPatrick Williams "interface_name": "xyz.openbmc_project.State.Host", 3040a360c2SBrad Bishop }, 31*75fe8cc4SPatrick Williams "settings": { 32*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.settings.Host", 33*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/settings/host0", 34*75fe8cc4SPatrick Williams "interface_name": "org.freedesktop.DBus.Properties", 3540a360c2SBrad Bishop }, 36*75fe8cc4SPatrick Williams "system": { 37*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.managers.System", 38*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/managers/System", 39*75fe8cc4SPatrick Williams "interface_name": "org.freedesktop.DBus.Properties", 40520f8b05SRatan Gupta }, 41*75fe8cc4SPatrick Williams "powersupplyredundancy": { 42*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.Sensors", 43*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/sensors/host/PowerSupplyRedundancy", 44*75fe8cc4SPatrick Williams "interface_name": "org.openbmc.SensorValue", 456b1f0f50SJayanth Othayoth }, 46*75fe8cc4SPatrick Williams "turboallowed": { 47*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.Sensors", 48*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/sensors/host/TurboAllowed", 49*75fe8cc4SPatrick Williams "interface_name": "org.openbmc.SensorValue", 50c2ef4fcfSDhruvaraj S }, 51*75fe8cc4SPatrick Williams "powersupplyderating": { 52*75fe8cc4SPatrick Williams "bus_name": "org.openbmc.Sensors", 53*75fe8cc4SPatrick Williams "object_name": "/org/openbmc/sensors/host/PowerSupplyDerating", 54*75fe8cc4SPatrick Williams "interface_name": "org.openbmc.SensorValue", 55e688d94bSJayanth Othayoth }, 5640a360c2SBrad Bishop} 5740a360c2SBrad Bishop 58291ae830SBrad Bishop 5940a360c2SBrad Bishopdef getInterface(bus, objs, key): 60291ae830SBrad Bishop obj = bus.get_object( 61*75fe8cc4SPatrick Williams objs[key]["bus_name"], objs[key]["object_name"], introspect=False 62*75fe8cc4SPatrick Williams ) 63*75fe8cc4SPatrick Williams return dbus.Interface(obj, objs[key]["interface_name"]) 6440a360c2SBrad Bishop 65291ae830SBrad Bishop 6640a360c2SBrad Bishopdef getProperty(bus, objs, key, prop): 67291ae830SBrad Bishop obj = bus.get_object( 68*75fe8cc4SPatrick Williams objs[key]["bus_name"], objs[key]["object_name"], introspect=False 69*75fe8cc4SPatrick Williams ) 7040a360c2SBrad Bishop intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) 71*75fe8cc4SPatrick Williams return intf.Get(objs[key]["interface_name"], prop) 7240a360c2SBrad Bishop 7324341f9dSAdriana Kobylak 7457eea1bfSAndrew Geisslerdef setProperty(bus, objs, key, prop, prop_value): 75*75fe8cc4SPatrick Williams obj = bus.get_object(objs[key]["bus_name"], objs[key]["object_name"]) 7657eea1bfSAndrew Geissler intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) 77*75fe8cc4SPatrick Williams return intf.Set(objs[key]["interface_name"], prop, prop_value) 7840a360c2SBrad Bishop 7924341f9dSAdriana Kobylak 8040a360c2SBrad Bishopbus = dbus.SystemBus() 81*75fe8cc4SPatrick Williamspgood = getProperty(bus, dbus_objects, "power", "pgood") 8240a360c2SBrad Bishop 83*75fe8cc4SPatrick Williamsif pgood == 1: 84*75fe8cc4SPatrick Williams intf = getInterface(bus, dbus_objects, "bootprogress") 8540a360c2SBrad Bishop intf.setValue("FW Progress, Starting OS") 86*75fe8cc4SPatrick Williams intf = getInterface(bus, dbus_objects, "occstatus0") 8740a360c2SBrad Bishop intf.setValue("Enabled") 88*75fe8cc4SPatrick Williams intf = getInterface(bus, dbus_objects, "occstatus1") 8940a360c2SBrad Bishop intf.setValue("Enabled") 9040a360c2SBrad Bishopelse: 91520f8b05SRatan Gupta # Power is off, so check power policy 92*75fe8cc4SPatrick Williams settings_intf = getInterface(bus, dbus_objects, "settings") 93*75fe8cc4SPatrick Williams system_intf = getInterface(bus, dbus_objects, "system") 94*75fe8cc4SPatrick Williams system_last_state = system_intf.Get( 95*75fe8cc4SPatrick Williams "org.openbmc.managers.System", "system_last_state" 96*75fe8cc4SPatrick Williams ) 97*75fe8cc4SPatrick Williams power_policy = settings_intf.Get( 98*75fe8cc4SPatrick Williams "org.openbmc.settings.Host", "power_policy" 99*75fe8cc4SPatrick Williams ) 100*75fe8cc4SPatrick Williams print( 101*75fe8cc4SPatrick Williams "Last System State:" 102*75fe8cc4SPatrick Williams + system_last_state 103*75fe8cc4SPatrick Williams + "Power Policy:" 104*75fe8cc4SPatrick Williams + power_policy 105*75fe8cc4SPatrick Williams ) 106520f8b05SRatan Gupta 107*75fe8cc4SPatrick Williams if power_policy == "ALWAYS_POWER_ON" or ( 108*75fe8cc4SPatrick Williams power_policy == "RESTORE_LAST_STATE" 109*75fe8cc4SPatrick Williams and system_last_state == "HOST_POWERED_ON" 110*75fe8cc4SPatrick Williams ): 111*75fe8cc4SPatrick Williams setProperty( 112*75fe8cc4SPatrick Williams bus, 113*75fe8cc4SPatrick Williams dbus_objects, 114*75fe8cc4SPatrick Williams "host", 115*75fe8cc4SPatrick Williams "RequestedHostTransition", 116*75fe8cc4SPatrick Williams "xyz.openbmc_project.State.Host.Transition.On", 117*75fe8cc4SPatrick Williams ) 118