Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import sys |
| 4 | import gobject |
| 5 | import dbus |
| 6 | import dbus.service |
| 7 | import dbus.mainloop.glib |
| 8 | |
| 9 | |
| 10 | dbus_objects = { |
| 11 | 'power' : { |
| 12 | 'bus_name' : 'org.openbmc.control.Power', |
| 13 | 'object_name' : '/org/openbmc/control/power0', |
| 14 | 'interface_name' : 'org.openbmc.control.Power' |
| 15 | }, |
Norman James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 16 | 'occstatus0' : { |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 17 | 'bus_name' : 'org.openbmc.Sensors', |
Norman James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 18 | 'object_name' : '/org/openbmc/sensors/host/cpu0/OccStatus', |
| 19 | 'interface_name' : 'org.openbmc.SensorValue' |
| 20 | }, |
| 21 | 'occstatus1' : { |
| 22 | 'bus_name' : 'org.openbmc.Sensors', |
| 23 | 'object_name' : '/org/openbmc/sensors/host/cpu1/OccStatus', |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 24 | 'interface_name' : 'org.openbmc.SensorValue' |
| 25 | }, |
| 26 | 'bootprogress' : { |
| 27 | 'bus_name' : 'org.openbmc.Sensors', |
| 28 | 'object_name' : '/org/openbmc/sensors/host/BootProgress', |
| 29 | 'interface_name' : 'org.openbmc.SensorValue' |
| 30 | }, |
Norman James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 31 | 'chassis' : { |
| 32 | 'bus_name' : 'org.openbmc.control.Chassis', |
| 33 | 'object_name' : '/org/openbmc/control/chassis0', |
| 34 | 'interface_name' : 'org.openbmc.control.Chassis' |
| 35 | }, |
Norman James | f5edb9e | 2016-01-31 13:32:24 -0600 | [diff] [blame] | 36 | 'settings' : { |
| 37 | 'bus_name' : 'org.openbmc.settings.Host', |
| 38 | 'object_name' : '/org/openbmc/settings/host0', |
| 39 | 'interface_name' : 'org.freedesktop.DBus.Properties' |
| 40 | }, |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | def getInterface(bus,objs,key): |
| 44 | obj = bus.get_object(objs[key]['bus_name'],objs[key]['object_name'],introspect=False) |
| 45 | return dbus.Interface(obj,objs[key]['interface_name']) |
| 46 | |
| 47 | def getProperty(bus,objs,key,prop): |
| 48 | obj = bus.get_object(objs[key]['bus_name'],objs[key]['object_name'],introspect=False) |
| 49 | intf = dbus.Interface(obj,dbus.PROPERTIES_IFACE) |
| 50 | return intf.Get(objs[key]['interface_name'],prop) |
| 51 | |
| 52 | |
| 53 | bus = dbus.SystemBus() |
| 54 | pgood = getProperty(bus,dbus_objects,'power','pgood') |
| 55 | |
| 56 | if (pgood == 1): |
| 57 | intf = getInterface(bus,dbus_objects,'bootprogress') |
| 58 | intf.setValue("FW Progress, Starting OS") |
Norman James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 59 | intf = getInterface(bus,dbus_objects,'occstatus0') |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 60 | intf.setValue("Enabled") |
Norman James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 61 | intf = getInterface(bus,dbus_objects,'occstatus1') |
| 62 | intf.setValue("Enabled") |
Norman James | f5edb9e | 2016-01-31 13:32:24 -0600 | [diff] [blame] | 63 | else: |
| 64 | ## Power is off, so check power policy |
| 65 | settings_intf = getInterface(bus,dbus_objects,'settings') |
| 66 | system_state = settings_intf.Get("org.openbmc.settings.Host","system_state") |
| 67 | power_policy = settings_intf.Get("org.openbmc.settings.Host","power_policy") |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 68 | |
Norman James | f5edb9e | 2016-01-31 13:32:24 -0600 | [diff] [blame] | 69 | print "Last System State: "+system_state+"; Power Policy: "+power_policy |
| 70 | chassis_intf = getInterface(bus,dbus_objects,'chassis') |
| 71 | if (power_policy == "ALWAYS_POWER_ON" or |
| 72 | (power_policy == "RESTORE_LAST_STATE" and |
| 73 | system_state =="HOST_POWERED_ON")): |
| 74 | chassis_intf.powerOn() |
Norman James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 75 | |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 76 | |