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