blob: 14f1268fa996222ae709f871264f3e9d1c6dd430 [file] [log] [blame]
Norman Jamesb4914ad2015-10-26 07:14:29 -05001#!/usr/bin/python
2
3import sys
Norman Jamesfacbca42015-11-09 15:58:14 -06004#import subprocess
Norman Jamesb4914ad2015-10-26 07:14:29 -05005import gobject
6import dbus
7import dbus.service
8import dbus.mainloop.glib
9import xml.etree.ElementTree as ET
Norman Jamesfacbca42015-11-09 15:58:14 -060010import json
Norman Jamesb4914ad2015-10-26 07:14:29 -050011
12def isDict(data):
Norman Jamesfacbca42015-11-09 15:58:14 -060013 if (str(type(data)) == "<type \'dict\'>"):
Norman Jamesb4914ad2015-10-26 07:14:29 -050014 return True
15 return False
16
17
18def printDict(name,data):
19 if (isDict(data)):
20 print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
21 print name
22 for p in data:
23 printDict(p,data[p])
24 else:
25 print name+" = "+str(data)
26
27def introspect(bus_name,obj_path,intf_name,method_name):
28 obj = bus.get_object(bus_name,obj_path)
29 introspect_iface = dbus.Interface(obj,"org.freedesktop.DBus.Introspectable")
30 tree = ET.ElementTree(ET.fromstring(introspect_iface.Introspect()))
31 #print method_name
32 #print introspect_iface.Introspect()
33 root = tree.getroot()
34 found = False
35 for node in root.iter('node'):
36 for intf in node.iter('interface'):
37 if (intf.attrib['name'] == intf_name):
38 for method in intf.iter('method'):
39 if (method.attrib['name'] == method_name):
40 for ar in method.iter('arg'):
41 if (ar.attrib['direction'] == "in"):
42 print "\t"+ar.attrib['name']+" ("+ar.attrib['type']+")"
43 found = True
44
45 return found
46
47
48dbus_objects = {
49 'power' : {
50 'bus_name' : 'org.openbmc.control.Power',
51 'object_name' : '/org/openbmc/control/power0',
52 'interface_name' : 'org.openbmc.control.Power'
53 },
54 'identify_led' : {
55 'bus_name' : 'org.openbmc.control.led',
Norman Jamesa23e7b82015-10-28 19:00:07 -050056 'object_name' : '/org/openbmc/control/led/IDENTIFY',
Norman Jamesb4914ad2015-10-26 07:14:29 -050057 'interface_name' : 'org.openbmc.Led'
58 },
59 'chassis' : {
60 'bus_name' : 'org.openbmc.control.Chassis',
61 'object_name' : '/org/openbmc/control/chassis0',
62 'interface_name' : 'org.openbmc.control.Chassis'
63 },
64 'poweron' : {
65 'bus_name' : 'org.openbmc.control.Chassis',
66 'object_name' : '/org/openbmc/control/chassis0',
67 'interface_name' : 'org.openbmc.control.Chassis',
68 'method' : 'powerOn',
69 },
70 'poweroff' : {
71 'bus_name' : 'org.openbmc.control.Chassis',
72 'object_name' : '/org/openbmc/control/chassis0',
73 'interface_name' : 'org.openbmc.control.Chassis',
74 'method' : 'powerOff',
75 },
76 'getsystemstate' : {
77 'bus_name' : 'org.openbmc.managers.System',
78 'object_name' : '/org/openbmc/managers/System',
79 'interface_name' : 'org.openbmc.managers.System',
80 'method' : 'getSystemState',
81 },
82 'bootprogress' : {
83 'bus_name' : 'org.openbmc.sensor.Power8Virtual',
84 'object_name' : '/org/openbmc/sensor/virtual/BootProgress',
85 'interface_name' : 'org.openbmc.SensorValue'
86 },
87 'updatebios' : {
88 'bus_name' : 'org.openbmc.control.Flash',
89 'object_name' : '/org/openbmc/control/flash/bios',
90 'interface_name' : 'org.openbmc.Flash',
91 'method' : 'updateViaTftp',
92 },
Norman Jamesfacbca42015-11-09 15:58:14 -060093 'bios' : {
94 'bus_name' : 'org.openbmc.control.Flash',
95 'object_name' : '/org/openbmc/control/flash/bios',
96 'interface_name' : 'org.openbmc.Flash',
97 },
Norman Jamesb4914ad2015-10-26 07:14:29 -050098 'getinventory' : {
99 'bus_name' : 'org.openbmc.managers.Inventory',
100 'object_name' : '/org/openbmc/inventory',
101 'interface_name' : 'org.openbmc.Object.Enumerate',
102 'method' : 'enumerate'
103 },
104 'getsensors' : {
105 'bus_name' : 'org.openbmc.managers.Sensors',
106 'object_name' : '/org/openbmc/sensors',
107 'interface_name' : 'org.openbmc.Object.Enumerate',
108 'method' : 'enumerate'
109 },
110 'inventorytest' : {
111 'bus_name' : 'org.openbmc.managers.Inventory',
112 'object_name' : '/org/openbmc/inventory/system/chassis/motherboard/cpu0',
113 'interface_name' : 'org.openbmc.InventoryItem',
114 'method' : 'update'
115 },
116
117}
118
119bus = dbus.SystemBus()
120
121
122if (len(sys.argv) == 1):
123 print "Usage: obmcutil [command] [[method] [*args]]"
124 print "\tIf [method] is blank, then all properties are printed\n"
125 print "Available commands:"
126 for name in dbus_objects:
127 m = ""
128 if (dbus_objects[name].has_key('method') == True):
129 m=" ("+dbus_objects[name]['interface_name']+"->"+dbus_objects[name]['method']+")"
130 print "\t"+name+m
131 exit(0)
132
133method_name = ""
134
135sys.argv.pop(0)
136objinfo = dbus_objects[sys.argv.pop(0)]
137
138if (objinfo.has_key('method')):
139 method_name = objinfo['method']
140elif (len(sys.argv)>0):
141 ## if command line args left and method not specified
142 ## then next arg must be method name
143 method_name = sys.argv.pop(0)
144
145bus_name = objinfo['bus_name']
146obj_path = objinfo['object_name']
147intf_name = objinfo['interface_name']
148obj = bus.get_object(bus_name,obj_path)
149
150if (method_name == ""):
151 intf = dbus.Interface(obj,"org.freedesktop.DBus.Properties")
152 props = intf.GetAll(intf_name)
153 for p in props:
154 print p+" = "+str(props[p])
155
156else:
157 methd = obj.get_dbus_method(method_name,intf_name)
158 try:
Norman James26f7dca2015-10-26 12:15:09 -0500159 ## too hard to do dicts from command line
160 ## hack just to test fru update function
Norman Jamesb4914ad2015-10-26 07:14:29 -0500161 if (method_name == "update"):
Norman James26f7dca2015-10-26 12:15:09 -0500162 tmp = { 'manufacturer' : sys.argv[0], 'part_num' : '3Nxxxx' }
Norman Jamesb4914ad2015-10-26 07:14:29 -0500163 methd(tmp)
164 else:
165 data = methd(*sys.argv)
Norman Jamesfacbca42015-11-09 15:58:14 -0600166 pydata = json.loads(json.dumps(data))
167 printDict("",pydata)
Norman Jamesb4914ad2015-10-26 07:14:29 -0500168 except Exception as e:
Norman James26f7dca2015-10-26 12:15:09 -0500169 print e
Norman Jamesb4914ad2015-10-26 07:14:29 -0500170 r = introspect(bus_name,obj_path,intf_name,method_name)
171 if (r == False):
172 print "ERROR: Invalid method: "+method_name
173 else:
174 print "ERROR: Incorrect arguments passed to method"
175
176
177