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