blob: 33847e532106053b3539406654267bc09d3381a1 [file] [log] [blame]
Norman James65a295a2015-09-26 22:21:10 -05001#!/usr/bin/env python
2
3import sys
4import subprocess
5import gobject
6import dbus
7import dbus.service
8import dbus.mainloop.glib
9import PropertyManager
10
11import Openbmc
12
Norman James19e45912015-10-04 20:19:41 -050013SENSOR_INTERFACE = "org.openbmc.SensorValue"
Norman Jamesdfdaca92015-09-27 22:11:15 -050014
15class IpmiBt(dbus.service.Object):
16 def __init__(self,bus,name):
17 dbus.service.Object.__init__(self,bus,name)
18
Norman James65a295a2015-09-26 22:21:10 -050019
20def getWatchdog():
21 obj = bus.get_object('org.openbmc.watchdog.Host',
22 '/org/openbmc/watchdog/HostWatchdog_0')
23 intf = dbus.Interface(obj, 'org.openbmc.Watchdog' )
24 return intf
25
26def getChassisControl():
27 obj = bus.get_object('org.openbmc.control.Chassis',
28 '/org/openbmc/control/Chassis')
29 intf = dbus.Interface(obj, 'org.openbmc.control.Chassis' )
30 return intf
31
32def prettyPrint(data):
33 for k in data.keys():
34 print k
35 for k2 in data[k].keys():
36 print "\t"+k2+" = "+str(data[k][k2])
37
Norman Jamesdfdaca92015-09-27 22:11:15 -050038
39
Norman James65a295a2015-09-26 22:21:10 -050040if __name__ == '__main__':
Norman James19e45912015-10-04 20:19:41 -050041 #dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Norman James5e792e32015-10-07 17:36:17 -050042 bus = Openbmc.getDBus()
43
Norman James19e45912015-10-04 20:19:41 -050044 #name = dbus.service.BusName(DBUS_NAME,bus)
45 #mainloop = gobject.MainLoop()
Norman Jamesdfdaca92015-09-27 22:11:15 -050046
Norman James65a295a2015-09-26 22:21:10 -050047 cmd = sys.argv[1]
48 data = None
49 ipmi_id = dbus.Byte(0)
50 if (len(sys.argv) > 2):
Norman James19e45912015-10-04 20:19:41 -050051 ipmi_id = sys.argv[2]
Norman James65a295a2015-09-26 22:21:10 -050052 if (len(sys.argv)>3):
53 data = sys.argv[3]
54
55 if (cmd == "poweron"):
56 intf = getChassisControl()
57 intf.powerOn()
58 elif (cmd == "poweroff"):
59 intf = getChassisControl()
60 intf.powerOff()
61 elif (cmd == "setsensor"):
Norman James19e45912015-10-04 20:19:41 -050062 intf_sys = Openbmc.getManagerInterface(bus,"System")
63 obj_info = intf_sys.getObjectFromId("SENSOR",ipmi_id)
64 obj_path = obj_info['obj_path']
65 bus_name = obj_info['bus_name']
66 if (obj_path != "" and bus_name != ""):
67 obj = bus.get_object(bus_name,obj_path)
68 intf = dbus.Interface(obj,SENSOR_INTERFACE)
69 intf.setValue(dbus.Byte(int(data)))
70
Norman James65a295a2015-09-26 22:21:10 -050071 elif (cmd == "getsensors"):
72 intf_sens = Openbmc.getManagerInterface(bus,"Sensors")
73 data = intf_sens.getSensors()
74 prettyPrint(data)
75 elif (cmd == "updatefru"):
Norman Jamesdfdaca92015-09-27 22:11:15 -050076 d = { 'manufacturer' : data }
Norman James19e45912015-10-04 20:19:41 -050077 intf_sys = Openbmc.getManagerInterface(bus,"System")
78 obj_info = intf_sys.getObjectFromId("FRU",ipmi_id)
79 obj_path = obj_info['obj_path']
80 bus_name = obj_info['bus_name']
81 if (obj_path != "" and bus_name != ""):
82 obj = bus.get_object(bus_name,obj_path)
83 intf = dbus.Interface(obj,"org.openbmc.InventoryItem")
84 intf.update(d)
85
Norman James65a295a2015-09-26 22:21:10 -050086 elif (cmd == "getfrus"):
87 intf_fru = Openbmc.getManagerInterface(bus,"Inventory")
Norman James19e45912015-10-04 20:19:41 -050088 data = intf_fru.getItems()
89 for i in data:
90 for k in data[i].keys():
91 print k+" = "+str(data[i][k])
Norman James31cda682015-10-06 16:52:43 -050092 elif (cmd == "updatefw"):
Norman Jamesf066e872015-10-07 15:29:51 -050093 obj = bus.get_object('org.openbmc.flash.Bios','/org/openbmc/flash/Bios_0')
94 intf = dbus.Interface(obj,"org.openbmc.Flash")
95 intf.updateViaTftp("bakerstreet.aus.stglabs.ibm.com","firmware.bin")
Norman James31cda682015-10-06 16:52:43 -050096 elif (cmd == "fwstatus"):
97 intf = Openbmc.getManagerInterface(bus,"Flash")
98 status = intf.getStatus()
99 for i in status:
100 print i+" = "+status[i]
Norman James65a295a2015-09-26 22:21:10 -0500101 elif (cmd == "pokewatchdog"):
102 intf = self.getWatchdog()
103 intf.poke()
104 elif (cmd == "statewatchdog"):
105 intf = self.getWatchdog()
106 intf.start()
107 else:
108 print "Unsupported command"
109
110
111
112
113
114