blob: 677d997269532c282b8903ecfabc6fea8b9c8850 [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 Jamesfacbca42015-11-09 15:58:14 -06005import json
Brad Bishop3cec2962016-06-21 20:51:54 -04006import xml.etree.ElementTree as ET
Norman Jamesb4914ad2015-10-26 07:14:29 -05007
Norman Jamesb4914ad2015-10-26 07:14:29 -05008dbus_objects = {
Andrew Geisslercae038e2016-12-19 15:29:10 -06009 'power': {
10 'bus_name': 'org.openbmc.control.Power',
11 'object_name': '/org/openbmc/control/power0',
12 'interface_name': 'org.openbmc.control.Power'
13 },
Andrew Geissler2cbbb672017-05-17 10:52:49 -050014 '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 Geisslercae038e2016-12-19 15:29:10 -060028 'poweron': {
Andrew Geissler25b9a852016-12-19 16:14:09 -060029 '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 Geisslercae038e2016-12-19 15:29:10 -060034 },
35 'poweroff': {
Andrew Geissler25b9a852016-12-19 16:14:09 -060036 '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 Geisslercae038e2016-12-19 15:29:10 -060041 },
Andrew Geissler8f8cbce2017-02-20 16:10:26 -060042 '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 Geisslercae038e2016-12-19 15:29:10 -060059 },
60 'bootprogress': {
George Keishing3be09952017-08-18 09:48:03 -050061 '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 Geisslercae038e2016-12-19 15:29:10 -060065 },
Norman Jamesb4914ad2015-10-26 07:14:29 -050066}
67
Andrew Jefferye4dcaef2017-10-11 18:08:01 +103068def run_one_command(dbus_bus, objinfo):
69 bus = objinfo['bus_name']
70 obj = objinfo['object_name']
71 iface = objinfo['interface_name']
72 dbus_obj = dbus_bus.get_object(bus, obj)
73
74 if (objinfo.has_key('property')):
75 prop = objinfo['property']
76 dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties")
77 if objinfo.has_key('value'):
78 dbus_iface.Set(iface, prop, objinfo['value'])
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 Jeffery7b376e72017-10-11 18:12:05 +103088def run_all_commands(dbus_bus, commands):
89 if isinstance(commands, dict):
90 run_one_command(dbus_bus, commands)
91 return
92
93 assert isinstance(commands, list)
94 for command in commands:
95 run_one_command(dbus_bus, dbus_objects[command])
96
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +103097def main():
98 # Commands that need to run multiple objects above
99 multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] }
Andrew Geissler8f8cbce2017-02-20 16:10:26 -0600100
Andrew Jefferybdb74352017-10-11 17:29:48 +1030101 dbus_bus = dbus.SystemBus()
Norman Jamesb4914ad2015-10-26 07:14:29 -0500102
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030103 if (len(sys.argv) == 1 or sys.argv[1] == "-h" or
104 (not(dbus_objects.has_key(sys.argv[1])) and
105 (not(multicmd_objects.has_key(sys.argv[1]))))):
106 print "Usage: obmcutil [command]"
107 print "Available commands:"
108 for name in sorted(dbus_objects.keys()):
109 m = ""
110 if (dbus_objects[name].has_key('property') == True):
111 m = " (" + dbus_objects[name]['interface_name'] + "->" + \
112 dbus_objects[name]['property'] + ")"
Norman Jamesb4914ad2015-10-26 07:14:29 -0500113
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030114 print "\t" + name + m
115 print "Multi-Commands:"
116 for name in sorted(multicmd_objects.keys()):
117 print "\t" + name + " -> " + ",".join(multicmd_objects[name])
118 exit(0)
Norman Jamesb4914ad2015-10-26 07:14:29 -0500119
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030120 sys.argv.pop(0)
Andrew Jeffery7b376e72017-10-11 18:12:05 +1030121 recipe = sys.argv.pop(0)
Norman Jamesb4914ad2015-10-26 07:14:29 -0500122
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030123 # Check if this is a multicmd command and update if it is
Andrew Jeffery7b376e72017-10-11 18:12:05 +1030124 if(multicmd_objects.has_key(recipe)):
125 recipe = multicmd_objects[recipe]
Norman Jamesb4914ad2015-10-26 07:14:29 -0500126
Andrew Jeffery7b376e72017-10-11 18:12:05 +1030127 run_all_commands(dbus_bus, recipe)
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030128
129if __name__ == "__main__":
130 main()