blob: 2f5518ede94dfadcb49e1d558faaa3fc3c3b6f00 [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 Jeffery44e6d9c2017-10-11 16:57:31 +103072 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 Jeffery44e6d9c2017-10-11 16:57:31 +103091 property_name = ""
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')):
103 property_name = objinfo['property']
Norman Jamesb4914ad2015-10-26 07:14:29 -0500104
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030105 bus_name = 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 Jefferyeee9c242017-10-11 17:24:24 +1030108 dbus_obj = bus.get_object(bus_name, obj)
Andrew Geissler8f8cbce2017-02-20 16:10:26 -0600109
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030110 if (property_name != ""):
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')):
113 property_value = objinfo['value']
Andrew Geissler8f8cbce2017-02-20 16:10:26 -0600114 else:
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030115 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 Jeffery563db9f2017-10-11 17:27:37 +1030120 dbus_iface.Set(iface, property_name, property_value)
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030121 else:
Andrew Jeffery563db9f2017-10-11 17:27:37 +1030122 prop = dbus_iface.Get(iface, property_name)
Andrew Jeffery44e6d9c2017-10-11 16:57:31 +1030123 print '{:<20}'.format(property_name+": ") + str(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()