1#!/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    },
16    'occstatus0' : {
17        'bus_name' : 'org.openbmc.Sensors',
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',
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    },
31    'chassis' : {
32        'bus_name' : 'org.openbmc.control.Chassis',
33        'object_name' : '/org/openbmc/control/chassis0',
34        'interface_name' : 'org.openbmc.control.Chassis'
35    },
36    'settings' : {
37        'bus_name' : 'org.openbmc.settings.Host',
38        'object_name' : '/org/openbmc/settings/host0',
39        'interface_name' : 'org.freedesktop.DBus.Properties'
40    },
41}
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")
59    intf = getInterface(bus,dbus_objects,'occstatus0')
60    intf.setValue("Enabled")
61    intf = getInterface(bus,dbus_objects,'occstatus1')
62    intf.setValue("Enabled")
63else:
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")
68
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()
75
76
77