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 = { |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [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 | }, |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [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 | }, |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [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 | }, |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [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 | }, |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 27 | 'chassis': { |
| 28 | 'bus_name': 'org.openbmc.control.Chassis', |
| 29 | 'object_name': '/org/openbmc/control/chassis0', |
| 30 | 'interface_name': 'org.openbmc.control.Chassis' |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 31 | }, |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [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 | }, |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [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' |
| 41 | }, |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 42 | } |
| 43 | |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 44 | |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 45 | def getInterface(bus, objs, key): |
| 46 | obj = bus.get_object( |
| 47 | objs[key]['bus_name'], objs[key]['object_name'], introspect=False) |
| 48 | return dbus.Interface(obj, objs[key]['interface_name']) |
| 49 | |
| 50 | |
| 51 | def getProperty(bus, objs, key, prop): |
| 52 | obj = bus.get_object( |
| 53 | objs[key]['bus_name'], objs[key]['object_name'], introspect=False) |
| 54 | intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
| 55 | return intf.Get(objs[key]['interface_name'], prop) |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 56 | |
| 57 | |
| 58 | bus = dbus.SystemBus() |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 59 | pgood = getProperty(bus, dbus_objects, 'power', 'pgood') |
Norman James | f20dd6b | 2015-12-18 15:00:55 -0600 | [diff] [blame] | 60 | |
| 61 | if (pgood == 1): |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 62 | intf = getInterface(bus, dbus_objects, 'bootprogress') |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 63 | intf.setValue("FW Progress, Starting OS") |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 64 | intf = getInterface(bus, dbus_objects, 'occstatus0') |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 65 | intf.setValue("Enabled") |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 66 | intf = getInterface(bus, dbus_objects, 'occstatus1') |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 67 | intf.setValue("Enabled") |
Norman James | f5edb9e | 2016-01-31 13:32:24 -0600 | [diff] [blame] | 68 | else: |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 69 | # Power is off, so check power policy |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 70 | settings_intf = getInterface(bus, dbus_objects, 'settings') |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 71 | system_intf = getInterface(bus, dbus_objects, 'system') |
| 72 | system_last_state = system_intf.Get("org.openbmc.managers.System", |
| 73 | "system_last_state") |
| 74 | power_policy = settings_intf.Get("org.openbmc.settings.Host", |
| 75 | "power_policy") |
| 76 | print "Last System State:"+system_last_state+"Power Policy:"+power_policy |
Brad Bishop | 291ae83 | 2016-08-30 20:12:12 -0400 | [diff] [blame] | 77 | chassis_intf = getInterface(bus, dbus_objects, 'chassis') |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 78 | |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 79 | if (power_policy == "ALWAYS_POWER_ON" or |
Ratan Gupta | 520f8b0 | 2016-09-06 21:47:05 +0530 | [diff] [blame] | 80 | (power_policy == "RESTORE_LAST_STATE" and |
| 81 | system_last_state == "HOST_POWERED_ON")): |
Ratan Gupta | b7484a0 | 2016-08-01 12:02:05 -0500 | [diff] [blame] | 82 | chassis_intf.powerOn() |
Brad Bishop | 5306675 | 2016-09-21 08:48:04 -0400 | [diff] [blame] | 83 | |
| 84 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |