blob: e62f2fced495561c8e1e82a0992770c4fdf790f7 [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 Jeffery44e6d9c2017-10-11 16:57:31 +103068def main():
69 # Commands that need to run multiple objects above
70 multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] }
Andrew Geissler8f8cbce2017-02-20 16:10:26 -060071
Andrew Jefferybdb74352017-10-11 17:29:48 +103072 dbus_bus = dbus.SystemBus()
Norman Jamesb4914ad2015-10-26 07:14:29 -050073
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +103074 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 Jamesb4914ad2015-10-26 07:14:29 -050084
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +103085 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 Jamesb4914ad2015-10-26 07:14:29 -050090
Andrew Jeffery97800bc2017-10-11 17:33:23 +103091 prop = ""
Norman Jamesb4914ad2015-10-26 07:14:29 -050092
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +103093 sys.argv.pop(0)
94 cmd = [sys.argv.pop(0)]
Norman Jamesb4914ad2015-10-26 07:14:29 -050095
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +103096 # 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 Jamesb4914ad2015-10-26 07:14:29 -050099
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030100 for c in cmd:
101 objinfo = dbus_objects[c]
102 if (objinfo.has_key('property')):
Andrew Jeffery97800bc2017-10-11 17:33:23 +1030103 prop = objinfo['property']
Norman Jamesb4914ad2015-10-26 07:14:29 -0500104
Andrew Jefferydc56a932017-10-11 17:30:44 +1030105 bus = objinfo['bus_name']
Andrew Jefferyeee9c242017-10-11 17:24:24 +1030106 obj = objinfo['object_name']
Andrew Jeffery563db9f2017-10-11 17:27:37 +1030107 iface = objinfo['interface_name']
Andrew Jefferydc56a932017-10-11 17:30:44 +1030108 dbus_obj = dbus_bus.get_object(bus, obj)
Andrew Geissler8f8cbce2017-02-20 16:10:26 -0600109
Andrew Jeffery97800bc2017-10-11 17:33:23 +1030110 if (prop != ""):
Andrew Jeffery687aaa42017-10-11 17:25:48 +1030111 dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties")
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030112 if (objinfo.has_key('value')):
Andrew Jeffery02154022017-10-11 17:34:33 +1030113 val = objinfo['value']
Andrew Geissler8f8cbce2017-02-20 16:10:26 -0600114 else:
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030115 if(len(sys.argv) > 0):
Andrew Jeffery02154022017-10-11 17:34:33 +1030116 val = eval(sys.argv.pop(0))
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030117 else:
Andrew Jeffery02154022017-10-11 17:34:33 +1030118 val = None
119 if(val is not None):
120 dbus_iface.Set(iface, prop, val)
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030121 else:
Andrew Jeffery97800bc2017-10-11 17:33:23 +1030122 dbus_prop = dbus_iface.Get(iface, prop)
123 print '{:<20}'.format(prop+": ") + str(dbus_prop)
Andrew Geissler8f8cbce2017-02-20 16:10:26 -0600124 else:
Andrew Jeffery687aaa42017-10-11 17:25:48 +1030125 dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties")
Andrew Jeffery563db9f2017-10-11 17:27:37 +1030126 props = dbus_iface.GetAll(iface)
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030127 for p in props:
128 print p + " = " + str(props[p])
129
130if __name__ == "__main__":
131 main()