Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 2 | |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 3 | import dbus |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 4 | |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 5 | dbus_objects = { |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 6 | "power": { |
| 7 | "bus_name": "org.openbmc.control.Power", |
| 8 | "object_name": "/org/openbmc/control/power0", |
| 9 | "interface_name": "org.openbmc.control.Power", |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 10 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 11 | "occstatus0": { |
| 12 | "bus_name": "org.openbmc.Sensors", |
| 13 | "object_name": "/org/openbmc/sensors/host/cpu0/OccStatus", |
| 14 | "interface_name": "org.openbmc.SensorValue", |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 15 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 16 | "occstatus1": { |
| 17 | "bus_name": "org.openbmc.Sensors", |
| 18 | "object_name": "/org/openbmc/sensors/host/cpu1/OccStatus", |
| 19 | "interface_name": "org.openbmc.SensorValue", |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 20 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 21 | "bootprogress": { |
| 22 | "bus_name": "org.openbmc.Sensors", |
| 23 | "object_name": "/org/openbmc/sensors/host/BootProgress", |
| 24 | "interface_name": "org.openbmc.SensorValue", |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 25 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 26 | "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 Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 30 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 31 | "settings": { |
| 32 | "bus_name": "org.openbmc.settings.Host", |
| 33 | "object_name": "/org/openbmc/settings/host0", |
| 34 | "interface_name": "org.freedesktop.DBus.Properties", |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 35 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 36 | "system": { |
| 37 | "bus_name": "org.openbmc.managers.System", |
| 38 | "object_name": "/org/openbmc/managers/System", |
| 39 | "interface_name": "org.freedesktop.DBus.Properties", |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 40 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 41 | "powersupplyredundancy": { |
| 42 | "bus_name": "org.openbmc.Sensors", |
| 43 | "object_name": "/org/openbmc/sensors/host/PowerSupplyRedundancy", |
| 44 | "interface_name": "org.openbmc.SensorValue", |
Jayanth Othayoth | 6b1f0f5 | 2017-03-30 00:02:35 -0500 | [diff] [blame] | 45 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 46 | "turboallowed": { |
| 47 | "bus_name": "org.openbmc.Sensors", |
| 48 | "object_name": "/org/openbmc/sensors/host/TurboAllowed", |
| 49 | "interface_name": "org.openbmc.SensorValue", |
Dhruvaraj S | c2ef4fc | 2017-03-21 02:08:56 -0500 | [diff] [blame] | 50 | }, |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 51 | "powersupplyderating": { |
| 52 | "bus_name": "org.openbmc.Sensors", |
| 53 | "object_name": "/org/openbmc/sensors/host/PowerSupplyDerating", |
| 54 | "interface_name": "org.openbmc.SensorValue", |
Jayanth Othayoth | e688d94 | 2017-03-27 08:31:22 -0500 | [diff] [blame] | 55 | }, |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 56 | } |
| 57 | |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 58 | |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 59 | def getInterface(bus, objs, key): |
| 60 | obj = bus.get_object( |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 61 | objs[key]["bus_name"], objs[key]["object_name"], introspect=False |
| 62 | ) |
| 63 | return dbus.Interface(obj, objs[key]["interface_name"]) |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 64 | |
| 65 | |
| 66 | def getProperty(bus, objs, key, prop): |
| 67 | obj = bus.get_object( |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 68 | objs[key]["bus_name"], objs[key]["object_name"], introspect=False |
| 69 | ) |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 70 | intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 71 | return intf.Get(objs[key]["interface_name"], prop) |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 72 | |
Adriana Kobylak | 24341f9 | 2018-01-26 15:07:23 -0600 | [diff] [blame] | 73 | |
Andrew Geissler | 57eea1b | 2016-12-20 10:00:30 -0600 | [diff] [blame] | 74 | def setProperty(bus, objs, key, prop, prop_value): |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 75 | obj = bus.get_object(objs[key]["bus_name"], objs[key]["object_name"]) |
Andrew Geissler | 57eea1b | 2016-12-20 10:00:30 -0600 | [diff] [blame] | 76 | intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 77 | return intf.Set(objs[key]["interface_name"], prop, prop_value) |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 78 | |
Adriana Kobylak | 24341f9 | 2018-01-26 15:07:23 -0600 | [diff] [blame] | 79 | |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 80 | bus = dbus.SystemBus() |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 81 | pgood = getProperty(bus, dbus_objects, "power", "pgood") |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 82 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 83 | if pgood == 1: |
| 84 | intf = getInterface(bus, dbus_objects, "bootprogress") |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 85 | intf.setValue("FW Progress, Starting OS") |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 86 | intf = getInterface(bus, dbus_objects, "occstatus0") |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 87 | intf.setValue("Enabled") |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 88 | intf = getInterface(bus, dbus_objects, "occstatus1") |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 89 | intf.setValue("Enabled") |
Norman James | f5edb9e | 2016-01-31 13:32:24 -0600 | [diff] [blame] | 90 | else: |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 91 | # Power is off, so check power policy |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 92 | 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 Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 106 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 107 | 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 Bishop | 5306675 | 2016-09-21 08:48:04 -0400 | [diff] [blame] | 118 | |
| 119 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |