blob: bff45ee3a9e0ec7e5a4c6080a4b01282416b538c [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
Norman Jamesf20dd6b2015-12-18 15:00:55 -06005dbus_objects = {
Patrick Williams75fe8cc2022-07-22 16:12:12 -05006 "power": {
7 "bus_name": "org.openbmc.control.Power",
8 "object_name": "/org/openbmc/control/power0",
9 "interface_name": "org.openbmc.control.Power",
Ratan Guptab7484a02016-08-01 12:02:05 -050010 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050011 "occstatus0": {
12 "bus_name": "org.openbmc.Sensors",
13 "object_name": "/org/openbmc/sensors/host/cpu0/OccStatus",
14 "interface_name": "org.openbmc.SensorValue",
Ratan Guptab7484a02016-08-01 12:02:05 -050015 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050016 "occstatus1": {
17 "bus_name": "org.openbmc.Sensors",
18 "object_name": "/org/openbmc/sensors/host/cpu1/OccStatus",
19 "interface_name": "org.openbmc.SensorValue",
Ratan Guptab7484a02016-08-01 12:02:05 -050020 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050021 "bootprogress": {
22 "bus_name": "org.openbmc.Sensors",
23 "object_name": "/org/openbmc/sensors/host/BootProgress",
24 "interface_name": "org.openbmc.SensorValue",
Ratan Guptab7484a02016-08-01 12:02:05 -050025 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050026 "host": {
27 "bus_name": "xyz.openbmc_project.State.Host",
28 "object_name": "/xyz/openbmc_project/state/host0",
29 "interface_name": "xyz.openbmc_project.State.Host",
Ratan Guptab7484a02016-08-01 12:02:05 -050030 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050031 "settings": {
32 "bus_name": "org.openbmc.settings.Host",
33 "object_name": "/org/openbmc/settings/host0",
34 "interface_name": "org.freedesktop.DBus.Properties",
Ratan Guptab7484a02016-08-01 12:02:05 -050035 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050036 "system": {
37 "bus_name": "org.openbmc.managers.System",
38 "object_name": "/org/openbmc/managers/System",
39 "interface_name": "org.freedesktop.DBus.Properties",
Ratan Gupta520f8b02016-09-06 21:47:05 +053040 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050041 "powersupplyredundancy": {
42 "bus_name": "org.openbmc.Sensors",
43 "object_name": "/org/openbmc/sensors/host/PowerSupplyRedundancy",
44 "interface_name": "org.openbmc.SensorValue",
Jayanth Othayoth6b1f0f52017-03-30 00:02:35 -050045 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050046 "turboallowed": {
47 "bus_name": "org.openbmc.Sensors",
48 "object_name": "/org/openbmc/sensors/host/TurboAllowed",
49 "interface_name": "org.openbmc.SensorValue",
Dhruvaraj Sc2ef4fc2017-03-21 02:08:56 -050050 },
Patrick Williams75fe8cc2022-07-22 16:12:12 -050051 "powersupplyderating": {
52 "bus_name": "org.openbmc.Sensors",
53 "object_name": "/org/openbmc/sensors/host/PowerSupplyDerating",
54 "interface_name": "org.openbmc.SensorValue",
Jayanth Othayothe688d942017-03-27 08:31:22 -050055 },
Norman Jamesf20dd6b2015-12-18 15:00:55 -060056}
57
Norman Jamesf20dd6b2015-12-18 15:00:55 -060058
Brad Bishop291ae832016-08-30 20:12:12 -040059def getInterface(bus, objs, key):
60 obj = bus.get_object(
Patrick Williams75fe8cc2022-07-22 16:12:12 -050061 objs[key]["bus_name"], objs[key]["object_name"], introspect=False
62 )
63 return dbus.Interface(obj, objs[key]["interface_name"])
Brad Bishop291ae832016-08-30 20:12:12 -040064
65
66def getProperty(bus, objs, key, prop):
67 obj = bus.get_object(
Patrick Williams75fe8cc2022-07-22 16:12:12 -050068 objs[key]["bus_name"], objs[key]["object_name"], introspect=False
69 )
Brad Bishop291ae832016-08-30 20:12:12 -040070 intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
Patrick Williams75fe8cc2022-07-22 16:12:12 -050071 return intf.Get(objs[key]["interface_name"], prop)
Norman Jamesf20dd6b2015-12-18 15:00:55 -060072
Adriana Kobylak24341f92018-01-26 15:07:23 -060073
Andrew Geissler57eea1b2016-12-20 10:00:30 -060074def setProperty(bus, objs, key, prop, prop_value):
Patrick Williams75fe8cc2022-07-22 16:12:12 -050075 obj = bus.get_object(objs[key]["bus_name"], objs[key]["object_name"])
Andrew Geissler57eea1b2016-12-20 10:00:30 -060076 intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
Patrick Williams75fe8cc2022-07-22 16:12:12 -050077 return intf.Set(objs[key]["interface_name"], prop, prop_value)
Norman Jamesf20dd6b2015-12-18 15:00:55 -060078
Adriana Kobylak24341f92018-01-26 15:07:23 -060079
Norman Jamesf20dd6b2015-12-18 15:00:55 -060080bus = dbus.SystemBus()
Patrick Williams75fe8cc2022-07-22 16:12:12 -050081pgood = getProperty(bus, dbus_objects, "power", "pgood")
Norman Jamesf20dd6b2015-12-18 15:00:55 -060082
Patrick Williams75fe8cc2022-07-22 16:12:12 -050083if pgood == 1:
84 intf = getInterface(bus, dbus_objects, "bootprogress")
Ratan Guptab7484a02016-08-01 12:02:05 -050085 intf.setValue("FW Progress, Starting OS")
Patrick Williams75fe8cc2022-07-22 16:12:12 -050086 intf = getInterface(bus, dbus_objects, "occstatus0")
Ratan Guptab7484a02016-08-01 12:02:05 -050087 intf.setValue("Enabled")
Patrick Williams75fe8cc2022-07-22 16:12:12 -050088 intf = getInterface(bus, dbus_objects, "occstatus1")
Ratan Guptab7484a02016-08-01 12:02:05 -050089 intf.setValue("Enabled")
Norman Jamesf5edb9e2016-01-31 13:32:24 -060090else:
Ratan Gupta520f8b02016-09-06 21:47:05 +053091 # Power is off, so check power policy
Patrick Williams75fe8cc2022-07-22 16:12:12 -050092 settings_intf = getInterface(bus, dbus_objects, "settings")
93 system_intf = getInterface(bus, dbus_objects, "system")
94 system_last_state = system_intf.Get(
95 "org.openbmc.managers.System", "system_last_state"
96 )
97 power_policy = settings_intf.Get(
98 "org.openbmc.settings.Host", "power_policy"
99 )
100 print(
101 "Last System State:"
102 + system_last_state
103 + "Power Policy:"
104 + power_policy
105 )
Ratan Gupta520f8b02016-09-06 21:47:05 +0530106
Patrick Williams75fe8cc2022-07-22 16:12:12 -0500107 if power_policy == "ALWAYS_POWER_ON" or (
108 power_policy == "RESTORE_LAST_STATE"
109 and system_last_state == "HOST_POWERED_ON"
110 ):
111 setProperty(
112 bus,
113 dbus_objects,
114 "host",
115 "RequestedHostTransition",
116 "xyz.openbmc_project.State.Host.Transition.On",
117 )
Brad Bishop53066752016-09-21 08:48:04 -0400118
119# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4