Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import sys |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 4 | import dbus |
Andrew Jeffery | 0b6883d | 2017-10-11 22:08:55 +1030 | [diff] [blame] | 5 | import argparse |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 6 | |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 7 | descriptors = { |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 8 | 'power': { |
| 9 | 'bus_name': 'org.openbmc.control.Power', |
| 10 | 'object_name': '/org/openbmc/control/power0', |
| 11 | 'interface_name': 'org.openbmc.control.Power' |
| 12 | }, |
Andrew Geissler | 2cbbb67 | 2017-05-17 10:52:49 -0500 | [diff] [blame] | 13 | 'chassison': { |
| 14 | 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 15 | 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 16 | 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 17 | 'property': 'RequestedPowerTransition', |
| 18 | 'value': 'xyz.openbmc_project.State.Chassis.Transition.On' |
| 19 | }, |
| 20 | 'chassisoff': { |
| 21 | 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 22 | 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 23 | 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 24 | 'property': 'RequestedPowerTransition', |
| 25 | 'value': 'xyz.openbmc_project.State.Chassis.Transition.Off' |
| 26 | }, |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 27 | 'poweron': { |
Andrew Geissler | 25b9a85 | 2016-12-19 16:14:09 -0600 | [diff] [blame] | 28 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 29 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 30 | 'interface_name': 'xyz.openbmc_project.State.Host', |
| 31 | 'property': 'RequestedHostTransition', |
| 32 | 'value': 'xyz.openbmc_project.State.Host.Transition.On' |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 33 | }, |
| 34 | 'poweroff': { |
Andrew Geissler | 25b9a85 | 2016-12-19 16:14:09 -0600 | [diff] [blame] | 35 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 36 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 37 | 'interface_name': 'xyz.openbmc_project.State.Host', |
| 38 | 'property': 'RequestedHostTransition', |
| 39 | 'value': 'xyz.openbmc_project.State.Host.Transition.Off' |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 40 | }, |
Andrew Geissler | 8f8cbce | 2017-02-20 16:10:26 -0600 | [diff] [blame] | 41 | 'bmcstate': { |
| 42 | 'bus_name': 'xyz.openbmc_project.State.BMC', |
| 43 | 'object_name': '/xyz/openbmc_project/state/bmc0', |
| 44 | 'interface_name': 'xyz.openbmc_project.State.BMC', |
| 45 | 'property': 'CurrentBMCState', |
| 46 | }, |
| 47 | 'chassisstate': { |
| 48 | 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 49 | 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 50 | 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 51 | 'property': 'CurrentPowerState', |
| 52 | }, |
| 53 | 'hoststate': { |
| 54 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 55 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 56 | 'interface_name': 'xyz.openbmc_project.State.Host', |
| 57 | 'property': 'CurrentHostState', |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 58 | }, |
| 59 | 'bootprogress': { |
George Keishing | 3be0995 | 2017-08-18 09:48:03 -0500 | [diff] [blame] | 60 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 61 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 62 | 'interface_name': 'xyz.openbmc_project.State.Boot.Progress', |
| 63 | 'property': 'BootProgress', |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 64 | }, |
Andrew Jeffery | 0b6883d | 2017-10-11 22:08:55 +1030 | [diff] [blame] | 65 | 'state' : ['bmcstate', 'chassisstate', 'hoststate'] |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 68 | def run_one_command(dbus_bus, descriptor): |
| 69 | bus = descriptor['bus_name'] |
| 70 | obj = descriptor['object_name'] |
| 71 | iface = descriptor['interface_name'] |
Andrew Jeffery | e4dcaef | 2017-10-11 18:08:01 +1030 | [diff] [blame] | 72 | dbus_obj = dbus_bus.get_object(bus, obj) |
| 73 | |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 74 | if (descriptor.has_key('property')): |
| 75 | prop = descriptor['property'] |
Andrew Jeffery | e4dcaef | 2017-10-11 18:08:01 +1030 | [diff] [blame] | 76 | dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties") |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 77 | if descriptor.has_key('value'): |
| 78 | dbus_iface.Set(iface, prop, descriptor['value']) |
Andrew Jeffery | e4dcaef | 2017-10-11 18:08:01 +1030 | [diff] [blame] | 79 | else: |
| 80 | dbus_prop = dbus_iface.Get(iface, prop) |
| 81 | print '{:<20}: {}'.format(prop, str(dbus_prop)) |
| 82 | else: |
| 83 | dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties") |
| 84 | props = dbus_iface.GetAll(iface) |
| 85 | for p in props: |
| 86 | print p + " = " + str(props[p]) |
| 87 | |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 88 | def run_all_commands(dbus_bus, recipe): |
| 89 | if isinstance(recipe, dict): |
| 90 | run_one_command(dbus_bus, recipe) |
Andrew Jeffery | 7b376e7 | 2017-10-11 18:12:05 +1030 | [diff] [blame] | 91 | return |
| 92 | |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 93 | assert isinstance(recipe, list) |
| 94 | for command in recipe: |
| 95 | run_one_command(dbus_bus, descriptors[command]) |
Andrew Jeffery | 7b376e7 | 2017-10-11 18:12:05 +1030 | [diff] [blame] | 96 | |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 97 | def main(): |
Andrew Jeffery | 0b6883d | 2017-10-11 22:08:55 +1030 | [diff] [blame] | 98 | parser = argparse.ArgumentParser() |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 99 | parser.add_argument('recipe', choices=sorted(descriptors.keys())) |
Andrew Jeffery | 0b6883d | 2017-10-11 22:08:55 +1030 | [diff] [blame] | 100 | args = parser.parse_args() |
Andrew Geissler | 8f8cbce | 2017-02-20 16:10:26 -0600 | [diff] [blame] | 101 | |
Andrew Jeffery | bdb7435 | 2017-10-11 17:29:48 +1030 | [diff] [blame] | 102 | dbus_bus = dbus.SystemBus() |
Andrew Jeffery | 0b6883d | 2017-10-11 22:08:55 +1030 | [diff] [blame] | 103 | try: |
Andrew Jeffery | c6b5deb | 2017-10-11 22:18:27 +1030 | [diff] [blame^] | 104 | run_all_commands(dbus_bus, descriptors[args.recipe], args) |
Andrew Jeffery | 0b6883d | 2017-10-11 22:08:55 +1030 | [diff] [blame] | 105 | finally: |
| 106 | dbus_bus.close() |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 107 | |
| 108 | if __name__ == "__main__": |
| 109 | main() |