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