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 |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 5 | |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 6 | dbus_objects = { |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [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' |
| 11 | }, |
Andrew Geissler | 2cbbb67 | 2017-05-17 10:52:49 -0500 | [diff] [blame] | 12 | 'chassison': { |
| 13 | 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 14 | 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 15 | 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 16 | 'property': 'RequestedPowerTransition', |
| 17 | 'value': 'xyz.openbmc_project.State.Chassis.Transition.On' |
| 18 | }, |
| 19 | 'chassisoff': { |
| 20 | 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 21 | 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 22 | 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 23 | 'property': 'RequestedPowerTransition', |
| 24 | 'value': 'xyz.openbmc_project.State.Chassis.Transition.Off' |
| 25 | }, |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 26 | 'poweron': { |
Andrew Geissler | 25b9a85 | 2016-12-19 16:14:09 -0600 | [diff] [blame] | 27 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 28 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 29 | 'interface_name': 'xyz.openbmc_project.State.Host', |
| 30 | 'property': 'RequestedHostTransition', |
| 31 | 'value': 'xyz.openbmc_project.State.Host.Transition.On' |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 32 | }, |
| 33 | 'poweroff': { |
Andrew Geissler | 25b9a85 | 2016-12-19 16:14:09 -0600 | [diff] [blame] | 34 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 35 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 36 | 'interface_name': 'xyz.openbmc_project.State.Host', |
| 37 | 'property': 'RequestedHostTransition', |
| 38 | 'value': 'xyz.openbmc_project.State.Host.Transition.Off' |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 39 | }, |
Andrew Geissler | 8f8cbce | 2017-02-20 16:10:26 -0600 | [diff] [blame] | 40 | 'bmcstate': { |
| 41 | 'bus_name': 'xyz.openbmc_project.State.BMC', |
| 42 | 'object_name': '/xyz/openbmc_project/state/bmc0', |
| 43 | 'interface_name': 'xyz.openbmc_project.State.BMC', |
| 44 | 'property': 'CurrentBMCState', |
| 45 | }, |
| 46 | 'chassisstate': { |
| 47 | 'bus_name': 'xyz.openbmc_project.State.Chassis', |
| 48 | 'object_name': '/xyz/openbmc_project/state/chassis0', |
| 49 | 'interface_name': 'xyz.openbmc_project.State.Chassis', |
| 50 | 'property': 'CurrentPowerState', |
| 51 | }, |
| 52 | 'hoststate': { |
| 53 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 54 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 55 | 'interface_name': 'xyz.openbmc_project.State.Host', |
| 56 | 'property': 'CurrentHostState', |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 57 | }, |
| 58 | 'bootprogress': { |
George Keishing | 3be0995 | 2017-08-18 09:48:03 -0500 | [diff] [blame] | 59 | 'bus_name': 'xyz.openbmc_project.State.Host', |
| 60 | 'object_name': '/xyz/openbmc_project/state/host0', |
| 61 | 'interface_name': 'xyz.openbmc_project.State.Boot.Progress', |
| 62 | 'property': 'BootProgress', |
Andrew Geissler | cae038e | 2016-12-19 15:29:10 -0600 | [diff] [blame] | 63 | }, |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 64 | } |
| 65 | |
Andrew Jeffery | e4dcaef | 2017-10-11 18:08:01 +1030 | [diff] [blame] | 66 | def run_one_command(dbus_bus, objinfo): |
| 67 | bus = objinfo['bus_name'] |
| 68 | obj = objinfo['object_name'] |
| 69 | iface = objinfo['interface_name'] |
| 70 | dbus_obj = dbus_bus.get_object(bus, obj) |
| 71 | |
| 72 | if (objinfo.has_key('property')): |
| 73 | prop = objinfo['property'] |
| 74 | dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties") |
| 75 | if objinfo.has_key('value'): |
| 76 | dbus_iface.Set(iface, prop, objinfo['value']) |
| 77 | else: |
| 78 | dbus_prop = dbus_iface.Get(iface, prop) |
| 79 | print '{:<20}: {}'.format(prop, str(dbus_prop)) |
| 80 | else: |
| 81 | dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties") |
| 82 | props = dbus_iface.GetAll(iface) |
| 83 | for p in props: |
| 84 | print p + " = " + str(props[p]) |
| 85 | |
Andrew Jeffery | 7b376e7 | 2017-10-11 18:12:05 +1030 | [diff] [blame] | 86 | def run_all_commands(dbus_bus, commands): |
| 87 | if isinstance(commands, dict): |
| 88 | run_one_command(dbus_bus, commands) |
| 89 | return |
| 90 | |
| 91 | assert isinstance(commands, list) |
| 92 | for command in commands: |
| 93 | run_one_command(dbus_bus, dbus_objects[command]) |
| 94 | |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 95 | def main(): |
| 96 | # Commands that need to run multiple objects above |
| 97 | multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] } |
Andrew Geissler | 8f8cbce | 2017-02-20 16:10:26 -0600 | [diff] [blame] | 98 | |
Andrew Jeffery | bdb7435 | 2017-10-11 17:29:48 +1030 | [diff] [blame] | 99 | dbus_bus = dbus.SystemBus() |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 100 | |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 101 | if (len(sys.argv) == 1 or sys.argv[1] == "-h" or |
| 102 | (not(dbus_objects.has_key(sys.argv[1])) and |
| 103 | (not(multicmd_objects.has_key(sys.argv[1]))))): |
| 104 | print "Usage: obmcutil [command]" |
| 105 | print "Available commands:" |
| 106 | for name in sorted(dbus_objects.keys()): |
| 107 | m = "" |
| 108 | if (dbus_objects[name].has_key('property') == True): |
| 109 | m = " (" + dbus_objects[name]['interface_name'] + "->" + \ |
| 110 | dbus_objects[name]['property'] + ")" |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 111 | |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 112 | print "\t" + name + m |
| 113 | print "Multi-Commands:" |
| 114 | for name in sorted(multicmd_objects.keys()): |
| 115 | print "\t" + name + " -> " + ",".join(multicmd_objects[name]) |
| 116 | exit(0) |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 117 | |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 118 | sys.argv.pop(0) |
Andrew Jeffery | 7b376e7 | 2017-10-11 18:12:05 +1030 | [diff] [blame] | 119 | recipe = sys.argv.pop(0) |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 120 | |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 121 | # Check if this is a multicmd command and update if it is |
Andrew Jeffery | 7b376e7 | 2017-10-11 18:12:05 +1030 | [diff] [blame] | 122 | if(multicmd_objects.has_key(recipe)): |
| 123 | recipe = multicmd_objects[recipe] |
Norman James | b4914ad | 2015-10-26 07:14:29 -0500 | [diff] [blame] | 124 | |
Andrew Jeffery | 7b376e7 | 2017-10-11 18:12:05 +1030 | [diff] [blame] | 125 | run_all_commands(dbus_bus, recipe) |
Andrew Jeffery | 44e6d9c | 2017-10-11 16:57:31 +1030 | [diff] [blame] | 126 | |
| 127 | if __name__ == "__main__": |
| 128 | main() |