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    'chassis': {
28        'bus_name': 'org.openbmc.control.Chassis',
29        'object_name': '/org/openbmc/control/chassis0',
30        'interface_name': 'org.openbmc.control.Chassis'
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}
38
39
40def getInterface(bus, objs, key):
41    obj = bus.get_object(
42        objs[key]['bus_name'], objs[key]['object_name'], introspect=False)
43    return dbus.Interface(obj, objs[key]['interface_name'])
44
45
46def getProperty(bus, objs, key, prop):
47    obj = bus.get_object(
48        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(
67        "org.openbmc.settings.Host", "system_state")
68    power_policy = settings_intf.Get(
69        "org.openbmc.settings.Host", "power_policy")
70
71    print "Last System State: "+system_state+";  Power Policy: "+power_policy
72    chassis_intf = getInterface(bus, dbus_objects, 'chassis')
73    if (power_policy == "ALWAYS_POWER_ON" or
74            (power_policy == "RESTORE_LAST_STATE" and
75             system_state == "HOST_POWERED_ON")):
76        chassis_intf.powerOn()
77
78# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
79