1#!/usr/bin/env python 2 3import dbus 4 5 6dbus_objects = { 7 'power': { 8 'bus_name': 'org.openbmc.control.Power', 9 'object_name': '/org/openbmc/control/power0', 10 'interface_name': 'org.openbmc.control.Power' 11 }, 12 'occstatus0': { 13 'bus_name': 'org.openbmc.Sensors', 14 'object_name': '/org/openbmc/sensors/host/cpu0/OccStatus', 15 'interface_name': 'org.openbmc.SensorValue' 16 }, 17 'occstatus1': { 18 'bus_name': 'org.openbmc.Sensors', 19 'object_name': '/org/openbmc/sensors/host/cpu1/OccStatus', 20 'interface_name': 'org.openbmc.SensorValue' 21 }, 22 'bootprogress': { 23 'bus_name': 'org.openbmc.Sensors', 24 'object_name': '/org/openbmc/sensors/host/BootProgress', 25 'interface_name': 'org.openbmc.SensorValue' 26 }, 27 'host': { 28 'bus_name': 'xyz.openbmc_project.State.Host', 29 'object_name': '/xyz/openbmc_project/state/host0', 30 'interface_name': 'xyz.openbmc_project.State.Host' 31 }, 32 'settings': { 33 'bus_name': 'org.openbmc.settings.Host', 34 'object_name': '/org/openbmc/settings/host0', 35 'interface_name': 'org.freedesktop.DBus.Properties' 36 }, 37 'system': { 38 'bus_name': 'org.openbmc.managers.System', 39 'object_name': '/org/openbmc/managers/System', 40 'interface_name': 'org.freedesktop.DBus.Properties' 41 }, 42 'powersupplyredundancy': { 43 'bus_name': 'org.openbmc.Sensors', 44 'object_name': '/org/openbmc/sensors/host/PowerSupplyRedundancy', 45 'interface_name': 'org.openbmc.SensorValue' 46 }, 47 'turboallowed': { 48 'bus_name': 'org.openbmc.Sensors', 49 'object_name': '/org/openbmc/sensors/host/TurboAllowed', 50 'interface_name': 'org.openbmc.SensorValue' 51 }, 52 'powersupplyderating': { 53 'bus_name': 'org.openbmc.Sensors', 54 'object_name': '/org/openbmc/sensors/host/PowerSupplyDerating', 55 'interface_name': 'org.openbmc.SensorValue' 56 }, 57} 58 59 60def getInterface(bus, objs, key): 61 obj = bus.get_object( 62 objs[key]['bus_name'], objs[key]['object_name'], introspect=False) 63 return dbus.Interface(obj, objs[key]['interface_name']) 64 65 66def getProperty(bus, objs, key, prop): 67 obj = bus.get_object( 68 objs[key]['bus_name'], objs[key]['object_name'], introspect=False) 69 intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) 70 return intf.Get(objs[key]['interface_name'], prop) 71 72 73def setProperty(bus, objs, key, prop, prop_value): 74 obj = bus.get_object( 75 objs[key]['bus_name'], objs[key]['object_name']) 76 intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) 77 return intf.Set(objs[key]['interface_name'], prop, prop_value) 78 79 80bus = dbus.SystemBus() 81pgood = getProperty(bus, dbus_objects, 'power', 'pgood') 82 83if (pgood == 1): 84 intf = getInterface(bus, dbus_objects, 'bootprogress') 85 intf.setValue("FW Progress, Starting OS") 86 intf = getInterface(bus, dbus_objects, 'occstatus0') 87 intf.setValue("Enabled") 88 intf = getInterface(bus, dbus_objects, 'occstatus1') 89 intf.setValue("Enabled") 90else: 91 # Power is off, so check power policy 92 settings_intf = getInterface(bus, dbus_objects, 'settings') 93 system_intf = getInterface(bus, dbus_objects, 'system') 94 system_last_state = system_intf.Get("org.openbmc.managers.System", 95 "system_last_state") 96 power_policy = settings_intf.Get("org.openbmc.settings.Host", 97 "power_policy") 98 print "Last System State:"+system_last_state+"Power Policy:"+power_policy 99 100 if (power_policy == "ALWAYS_POWER_ON" or 101 (power_policy == "RESTORE_LAST_STATE" and 102 system_last_state == "HOST_POWERED_ON")): 103 setProperty(bus, dbus_objects, 'host', 'RequestedHostTransition', 104 'xyz.openbmc_project.State.Host.Transition.On') 105 106# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 107