blob: cc2ae10e22f7d115b06b5e8c030cf42e72015602 [file] [log] [blame]
Brad Bishop291ae832016-08-30 20:12:12 -04001#!/usr/bin/env python
Norman Jamesf20dd6b2015-12-18 15:00:55 -06002
Norman Jamesf20dd6b2015-12-18 15:00:55 -06003import dbus
Norman Jamesf20dd6b2015-12-18 15:00:55 -06004
5
6dbus_objects = {
Brad Bishop291ae832016-08-30 20:12:12 -04007 'power': {
8 'bus_name': 'org.openbmc.control.Power',
9 'object_name': '/org/openbmc/control/power0',
10 'interface_name': 'org.openbmc.control.Power'
Ratan Guptab7484a02016-08-01 12:02:05 -050011 },
Brad Bishop291ae832016-08-30 20:12:12 -040012 'occstatus0': {
13 'bus_name': 'org.openbmc.Sensors',
14 'object_name': '/org/openbmc/sensors/host/cpu0/OccStatus',
15 'interface_name': 'org.openbmc.SensorValue'
Ratan Guptab7484a02016-08-01 12:02:05 -050016 },
Brad Bishop291ae832016-08-30 20:12:12 -040017 'occstatus1': {
18 'bus_name': 'org.openbmc.Sensors',
19 'object_name': '/org/openbmc/sensors/host/cpu1/OccStatus',
20 'interface_name': 'org.openbmc.SensorValue'
Ratan Guptab7484a02016-08-01 12:02:05 -050021 },
Brad Bishop291ae832016-08-30 20:12:12 -040022 'bootprogress': {
23 'bus_name': 'org.openbmc.Sensors',
24 'object_name': '/org/openbmc/sensors/host/BootProgress',
25 'interface_name': 'org.openbmc.SensorValue'
Ratan Guptab7484a02016-08-01 12:02:05 -050026 },
Andrew Geissler57eea1b2016-12-20 10:00:30 -060027 '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'
Ratan Guptab7484a02016-08-01 12:02:05 -050031 },
Brad Bishop291ae832016-08-30 20:12:12 -040032 'settings': {
33 'bus_name': 'org.openbmc.settings.Host',
34 'object_name': '/org/openbmc/settings/host0',
35 'interface_name': 'org.freedesktop.DBus.Properties'
Ratan Guptab7484a02016-08-01 12:02:05 -050036 },
Ratan Gupta520f8b02016-09-06 21:47:05 +053037 'system': {
38 'bus_name': 'org.openbmc.managers.System',
39 'object_name': '/org/openbmc/managers/System',
40 'interface_name': 'org.freedesktop.DBus.Properties'
41 },
Dhruvaraj Sc2ef4fc2017-03-21 02:08:56 -050042 'powersupplyredundancy': {
43 'bus_name': 'org.openbmc.Sensors',
44 'object_name': '/org/openbmc/sensors/host/PowerSupplyRedundancy',
Jayanth Othayothc99bd0c2017-03-29 04:27:35 -050045 'interface_name': 'org.openbmc.SensorValue'
Jayanth Othayoth6b1f0f52017-03-30 00:02:35 -050046 },
Jayanth Othayoth3a3ac922017-03-22 05:46:44 -050047 'turboallowed': {
48 'bus_name': 'org.openbmc.Sensors',
49 'object_name': '/org/openbmc/sensors/host/TurboAllowed',
50 'interface_name': 'org.openbmc.SensorValue'
Dhruvaraj Sc2ef4fc2017-03-21 02:08:56 -050051 },
Jayanth Othayothe688d942017-03-27 08:31:22 -050052 'powersupplyderating': {
53 'bus_name': 'org.openbmc.Sensors',
54 'object_name': '/org/openbmc/sensors/host/PowerSupplyDerating',
55 'interface_name': 'org.openbmc.SensorValue'
56 },
Norman Jamesf20dd6b2015-12-18 15:00:55 -060057}
58
Norman Jamesf20dd6b2015-12-18 15:00:55 -060059
Brad Bishop291ae832016-08-30 20:12:12 -040060def 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)
Norman Jamesf20dd6b2015-12-18 15:00:55 -060071
Andrew Geissler57eea1b2016-12-20 10:00:30 -060072def setProperty(bus, objs, key, prop, prop_value):
73 obj = bus.get_object(
74 objs[key]['bus_name'], objs[key]['object_name'])
75 intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
76 return intf.Set(objs[key]['interface_name'], prop, prop_value)
Norman Jamesf20dd6b2015-12-18 15:00:55 -060077
78bus = dbus.SystemBus()
Brad Bishop291ae832016-08-30 20:12:12 -040079pgood = getProperty(bus, dbus_objects, 'power', 'pgood')
Norman Jamesf20dd6b2015-12-18 15:00:55 -060080
81if (pgood == 1):
Brad Bishop291ae832016-08-30 20:12:12 -040082 intf = getInterface(bus, dbus_objects, 'bootprogress')
Ratan Guptab7484a02016-08-01 12:02:05 -050083 intf.setValue("FW Progress, Starting OS")
Brad Bishop291ae832016-08-30 20:12:12 -040084 intf = getInterface(bus, dbus_objects, 'occstatus0')
Ratan Guptab7484a02016-08-01 12:02:05 -050085 intf.setValue("Enabled")
Brad Bishop291ae832016-08-30 20:12:12 -040086 intf = getInterface(bus, dbus_objects, 'occstatus1')
Ratan Guptab7484a02016-08-01 12:02:05 -050087 intf.setValue("Enabled")
Norman Jamesf5edb9e2016-01-31 13:32:24 -060088else:
Ratan Gupta520f8b02016-09-06 21:47:05 +053089 # Power is off, so check power policy
Brad Bishop291ae832016-08-30 20:12:12 -040090 settings_intf = getInterface(bus, dbus_objects, 'settings')
Ratan Gupta520f8b02016-09-06 21:47:05 +053091 system_intf = getInterface(bus, dbus_objects, 'system')
92 system_last_state = system_intf.Get("org.openbmc.managers.System",
93 "system_last_state")
94 power_policy = settings_intf.Get("org.openbmc.settings.Host",
95 "power_policy")
96 print "Last System State:"+system_last_state+"Power Policy:"+power_policy
Ratan Gupta520f8b02016-09-06 21:47:05 +053097
Ratan Guptab7484a02016-08-01 12:02:05 -050098 if (power_policy == "ALWAYS_POWER_ON" or
Ratan Gupta520f8b02016-09-06 21:47:05 +053099 (power_policy == "RESTORE_LAST_STATE" and
100 system_last_state == "HOST_POWERED_ON")):
Andrew Geissler57eea1b2016-12-20 10:00:30 -0600101 setProperty(bus, dbus_objects, 'host', 'RequestedHostTransition',
102 'xyz.openbmc_project.State.Host.Transition.On')
Brad Bishop53066752016-09-21 08:48:04 -0400103
104# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4