blob: 290fc332159088e8be86bf4dda6c22b855a1ed32 [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 James65a295a2015-09-26 22:21:10 -050042 bus = dbus.SessionBus()
Norman James19e45912015-10-04 20:19:41 -050043 #name = dbus.service.BusName(DBUS_NAME,bus)
44 #mainloop = gobject.MainLoop()
Norman Jamesdfdaca92015-09-27 22:11:15 -050045
Norman James65a295a2015-09-26 22:21:10 -050046 cmd = sys.argv[1]
47 data = None
48 ipmi_id = dbus.Byte(0)
49 if (len(sys.argv) > 2):
Norman James19e45912015-10-04 20:19:41 -050050 ipmi_id = sys.argv[2]
Norman James65a295a2015-09-26 22:21:10 -050051 if (len(sys.argv)>3):
52 data = sys.argv[3]
53
54 if (cmd == "poweron"):
55 intf = getChassisControl()
56 intf.powerOn()
57 elif (cmd == "poweroff"):
58 intf = getChassisControl()
59 intf.powerOff()
60 elif (cmd == "setsensor"):
Norman James19e45912015-10-04 20:19:41 -050061 intf_sys = Openbmc.getManagerInterface(bus,"System")
62 obj_info = intf_sys.getObjectFromId("SENSOR",ipmi_id)
63 obj_path = obj_info['obj_path']
64 bus_name = obj_info['bus_name']
65 if (obj_path != "" and bus_name != ""):
66 obj = bus.get_object(bus_name,obj_path)
67 intf = dbus.Interface(obj,SENSOR_INTERFACE)
68 intf.setValue(dbus.Byte(int(data)))
69
Norman James65a295a2015-09-26 22:21:10 -050070 elif (cmd == "getsensors"):
71 intf_sens = Openbmc.getManagerInterface(bus,"Sensors")
72 data = intf_sens.getSensors()
73 prettyPrint(data)
74 elif (cmd == "updatefru"):
Norman Jamesdfdaca92015-09-27 22:11:15 -050075 d = { 'manufacturer' : data }
Norman James19e45912015-10-04 20:19:41 -050076 intf_sys = Openbmc.getManagerInterface(bus,"System")
77 obj_info = intf_sys.getObjectFromId("FRU",ipmi_id)
78 obj_path = obj_info['obj_path']
79 bus_name = obj_info['bus_name']
80 if (obj_path != "" and bus_name != ""):
81 obj = bus.get_object(bus_name,obj_path)
82 intf = dbus.Interface(obj,"org.openbmc.InventoryItem")
83 intf.update(d)
84
Norman James65a295a2015-09-26 22:21:10 -050085 elif (cmd == "getfrus"):
86 intf_fru = Openbmc.getManagerInterface(bus,"Inventory")
Norman James19e45912015-10-04 20:19:41 -050087 data = intf_fru.getItems()
88 for i in data:
89 for k in data[i].keys():
90 print k+" = "+str(data[i][k])
Norman James65a295a2015-09-26 22:21:10 -050091 elif (cmd == "pokewatchdog"):
92 intf = self.getWatchdog()
93 intf.poke()
94 elif (cmd == "statewatchdog"):
95 intf = self.getWatchdog()
96 intf.start()
97 else:
98 print "Unsupported command"
99
100
101
102
103
104