blob: 5bd8fdcb4841f1777b5278ac1b55a31769880119 [file] [log] [blame]
Norman Jamesf20dd6b2015-12-18 15:00:55 -06001#!/usr/bin/python
2
3import sys
4import gobject
5import dbus
6import dbus.service
7import dbus.mainloop.glib
8
9
10dbus_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 James86f2a072016-01-30 22:48:54 -060016 'occstatus0' : {
Norman Jamesf20dd6b2015-12-18 15:00:55 -060017 'bus_name' : 'org.openbmc.Sensors',
Norman James86f2a072016-01-30 22:48:54 -060018 '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 Jamesf20dd6b2015-12-18 15:00:55 -060024 '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 James86f2a072016-01-30 22:48:54 -060031 'chassis' : {
32 'bus_name' : 'org.openbmc.control.Chassis',
33 'object_name' : '/org/openbmc/control/chassis0',
34 'interface_name' : 'org.openbmc.control.Chassis'
35 },
Norman Jamesf5edb9e2016-01-31 13:32:24 -060036 'settings' : {
37 'bus_name' : 'org.openbmc.settings.Host',
38 'object_name' : '/org/openbmc/settings/host0',
39 'interface_name' : 'org.freedesktop.DBus.Properties'
40 },
Norman Jamesf20dd6b2015-12-18 15:00:55 -060041}
42
43def 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
47def 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
53bus = dbus.SystemBus()
54pgood = getProperty(bus,dbus_objects,'power','pgood')
55
56if (pgood == 1):
57 intf = getInterface(bus,dbus_objects,'bootprogress')
58 intf.setValue("FW Progress, Starting OS")
Norman James86f2a072016-01-30 22:48:54 -060059 intf = getInterface(bus,dbus_objects,'occstatus0')
Norman Jamesf20dd6b2015-12-18 15:00:55 -060060 intf.setValue("Enabled")
Norman James86f2a072016-01-30 22:48:54 -060061 intf = getInterface(bus,dbus_objects,'occstatus1')
62 intf.setValue("Enabled")
Norman Jamesf5edb9e2016-01-31 13:32:24 -060063else:
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 Jamesf20dd6b2015-12-18 15:00:55 -060068
Norman Jamesf5edb9e2016-01-31 13:32:24 -060069 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 James86f2a072016-01-30 22:48:54 -060075
Norman Jamesf20dd6b2015-12-18 15:00:55 -060076