blob: 42f34e5a0e6e182560f44a008a102d05811efd70 [file] [log] [blame]
Norman Jamesb4914ad2015-10-26 07:14:29 -05001#!/usr/bin/python
2
3import sys
Norman Jamesb4914ad2015-10-26 07:14:29 -05004import dbus
Norman Jamesb4914ad2015-10-26 07:14:29 -05005
Norman Jamesb4914ad2015-10-26 07:14:29 -05006dbus_objects = {
Andrew Geisslercae038e2016-12-19 15:29:10 -06007 'power': {
8 'bus_name': 'org.openbmc.control.Power',
9 'object_name': '/org/openbmc/control/power0',
10 'interface_name': 'org.openbmc.control.Power'
11 },
Andrew Geissler2cbbb672017-05-17 10:52:49 -050012 '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 Geisslercae038e2016-12-19 15:29:10 -060026 'poweron': {
Andrew Geissler25b9a852016-12-19 16:14:09 -060027 '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 Geisslercae038e2016-12-19 15:29:10 -060032 },
33 'poweroff': {
Andrew Geissler25b9a852016-12-19 16:14:09 -060034 '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 Geisslercae038e2016-12-19 15:29:10 -060039 },
Andrew Geissler8f8cbce2017-02-20 16:10:26 -060040 '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 Geisslercae038e2016-12-19 15:29:10 -060057 },
58 'bootprogress': {
George Keishing3be09952017-08-18 09:48:03 -050059 '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 Geisslercae038e2016-12-19 15:29:10 -060063 },
Norman Jamesb4914ad2015-10-26 07:14:29 -050064}
65
Andrew Jefferye4dcaef2017-10-11 18:08:01 +103066def 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 Jeffery7b376e72017-10-11 18:12:05 +103086def 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 Jeffery44e6d9c2017-10-11 16:57:31 +103095def main():
96 # Commands that need to run multiple objects above
97 multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] }
Andrew Geissler8f8cbce2017-02-20 16:10:26 -060098
Andrew Jefferybdb74352017-10-11 17:29:48 +103099 dbus_bus = dbus.SystemBus()
Norman Jamesb4914ad2015-10-26 07:14:29 -0500100
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030101 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 Jamesb4914ad2015-10-26 07:14:29 -0500111
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030112 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 Jamesb4914ad2015-10-26 07:14:29 -0500117
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030118 sys.argv.pop(0)
Andrew Jeffery7b376e72017-10-11 18:12:05 +1030119 recipe = sys.argv.pop(0)
Norman Jamesb4914ad2015-10-26 07:14:29 -0500120
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030121 # Check if this is a multicmd command and update if it is
Andrew Jeffery7b376e72017-10-11 18:12:05 +1030122 if(multicmd_objects.has_key(recipe)):
123 recipe = multicmd_objects[recipe]
Norman Jamesb4914ad2015-10-26 07:14:29 -0500124
Andrew Jeffery7b376e72017-10-11 18:12:05 +1030125 run_all_commands(dbus_bus, recipe)
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030126
127if __name__ == "__main__":
128 main()