blob: 8c39e8b06b7533ab0f358dbff5a988f9db45fd86 [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 = {
Patrick Williams75fe8cc2022-07-22 16:12:12 -05007 "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 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050012 "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 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050017 "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 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050022 "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 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050027 "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 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050032 "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 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050037 "system": {
38 "bus_name": "org.openbmc.managers.System",
39 "object_name": "/org/openbmc/managers/System",
40 "interface_name": "org.freedesktop.DBus.Properties",
Ratan Gupta520f8b02016-09-06 21:47:05 +053041 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050042 "powersupplyredundancy": {
43 "bus_name": "org.openbmc.Sensors",
44 "object_name": "/org/openbmc/sensors/host/PowerSupplyRedundancy",
45 "interface_name": "org.openbmc.SensorValue",
Jayanth Othayoth6b1f0f52017-03-30 00:02:35 -050046 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -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 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050052 "powersupplyderating": {
53 "bus_name": "org.openbmc.Sensors",
54 "object_name": "/org/openbmc/sensors/host/PowerSupplyDerating",
55 "interface_name": "org.openbmc.SensorValue",
Jayanth Othayothe688d942017-03-27 08:31:22 -050056 },
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(
Patrick Williams75fe8cc2022-07-22 16:12:12 -050062 objs[key]["bus_name"], objs[key]["object_name"], introspect=False
63 )
64 return dbus.Interface(obj, objs[key]["interface_name"])
Brad Bishop291ae832016-08-30 20:12:12 -040065
66
67def getProperty(bus, objs, key, prop):
68 obj = bus.get_object(
Patrick Williams75fe8cc2022-07-22 16:12:12 -050069 objs[key]["bus_name"], objs[key]["object_name"], introspect=False
70 )
Brad Bishop291ae832016-08-30 20:12:12 -040071 intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
Patrick Williams75fe8cc2022-07-22 16:12:12 -050072 return intf.Get(objs[key]["interface_name"], prop)
Norman Jamesf20dd6b2015-12-18 15:00:55 -060073
Adriana Kobylak24341f92018-01-26 15:07:23 -060074
Andrew Geissler57eea1b2016-12-20 10:00:30 -060075def setProperty(bus, objs, key, prop, prop_value):
Patrick Williams75fe8cc2022-07-22 16:12:12 -050076 obj = bus.get_object(objs[key]["bus_name"], objs[key]["object_name"])
Andrew Geissler57eea1b2016-12-20 10:00:30 -060077 intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
Patrick Williams75fe8cc2022-07-22 16:12:12 -050078 return intf.Set(objs[key]["interface_name"], prop, prop_value)
Norman Jamesf20dd6b2015-12-18 15:00:55 -060079
Adriana Kobylak24341f92018-01-26 15:07:23 -060080
Norman Jamesf20dd6b2015-12-18 15:00:55 -060081bus = dbus.SystemBus()
Patrick Williams75fe8cc2022-07-22 16:12:12 -050082pgood = getProperty(bus, dbus_objects, "power", "pgood")
Norman Jamesf20dd6b2015-12-18 15:00:55 -060083
Patrick Williams75fe8cc2022-07-22 16:12:12 -050084if pgood == 1:
85 intf = getInterface(bus, dbus_objects, "bootprogress")
Ratan Guptab7484a02016-08-01 12:02:05 -050086 intf.setValue("FW Progress, Starting OS")
Patrick Williams75fe8cc2022-07-22 16:12:12 -050087 intf = getInterface(bus, dbus_objects, "occstatus0")
Ratan Guptab7484a02016-08-01 12:02:05 -050088 intf.setValue("Enabled")
Patrick Williams75fe8cc2022-07-22 16:12:12 -050089 intf = getInterface(bus, dbus_objects, "occstatus1")
Ratan Guptab7484a02016-08-01 12:02:05 -050090 intf.setValue("Enabled")
Norman Jamesf5edb9e2016-01-31 13:32:24 -060091else:
Ratan Gupta520f8b02016-09-06 21:47:05 +053092 # Power is off, so check power policy
Patrick Williams75fe8cc2022-07-22 16:12:12 -050093 settings_intf = getInterface(bus, dbus_objects, "settings")
94 system_intf = getInterface(bus, dbus_objects, "system")
95 system_last_state = system_intf.Get(
96 "org.openbmc.managers.System", "system_last_state"
97 )
98 power_policy = settings_intf.Get(
99 "org.openbmc.settings.Host", "power_policy"
100 )
101 print(
102 "Last System State:"
103 + system_last_state
104 + "Power Policy:"
105 + power_policy
106 )
Ratan Gupta520f8b02016-09-06 21:47:05 +0530107
Patrick Williams75fe8cc2022-07-22 16:12:12 -0500108 if power_policy == "ALWAYS_POWER_ON" or (
109 power_policy == "RESTORE_LAST_STATE"
110 and system_last_state == "HOST_POWERED_ON"
111 ):
112 setProperty(
113 bus,
114 dbus_objects,
115 "host",
116 "RequestedHostTransition",
117 "xyz.openbmc_project.State.Host.Transition.On",
118 )
Brad Bishop53066752016-09-21 08:48:04 -0400119
120# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4