Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import subprocess |
| 5 | import gobject |
| 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | import PropertyManager |
| 10 | |
| 11 | import Openbmc |
| 12 | |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 13 | DBUS_NAME = 'org.openbmc.sensors.IpmiBt' |
| 14 | OBJ_NAME = '/org/openbmc/sensors/IpmiBt' |
| 15 | |
| 16 | class IpmiBt(dbus.service.Object): |
| 17 | def __init__(self,bus,name): |
| 18 | dbus.service.Object.__init__(self,bus,name) |
| 19 | |
| 20 | @dbus.service.signal('org.openbmc.sensors.IpmiBt') |
| 21 | def SetSensor(self, ipmi_id, value): |
| 22 | pass |
| 23 | |
| 24 | @dbus.service.signal('org.openbmc.sensors.IpmiBt') |
| 25 | def UpdateFru(self, ipmi_id, data): |
| 26 | pass |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def getWatchdog(): |
| 30 | obj = bus.get_object('org.openbmc.watchdog.Host', |
| 31 | '/org/openbmc/watchdog/HostWatchdog_0') |
| 32 | intf = dbus.Interface(obj, 'org.openbmc.Watchdog' ) |
| 33 | return intf |
| 34 | |
| 35 | def getChassisControl(): |
| 36 | obj = bus.get_object('org.openbmc.control.Chassis', |
| 37 | '/org/openbmc/control/Chassis') |
| 38 | intf = dbus.Interface(obj, 'org.openbmc.control.Chassis' ) |
| 39 | return intf |
| 40 | |
| 41 | def prettyPrint(data): |
| 42 | for k in data.keys(): |
| 43 | print k |
| 44 | for k2 in data[k].keys(): |
| 45 | print "\t"+k2+" = "+str(data[k][k2]) |
| 46 | |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 47 | |
| 48 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 49 | if __name__ == '__main__': |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 50 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 51 | bus = dbus.SessionBus() |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 52 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 53 | obj = IpmiBt(bus,OBJ_NAME) |
| 54 | mainloop = gobject.MainLoop() |
| 55 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 56 | cmd = sys.argv[1] |
| 57 | data = None |
| 58 | ipmi_id = dbus.Byte(0) |
| 59 | if (len(sys.argv) > 2): |
| 60 | ipmi_id = dbus.Byte(int(sys.argv[2])) |
| 61 | if (len(sys.argv)>3): |
| 62 | data = sys.argv[3] |
| 63 | |
| 64 | if (cmd == "poweron"): |
| 65 | intf = getChassisControl() |
| 66 | intf.powerOn() |
| 67 | elif (cmd == "poweroff"): |
| 68 | intf = getChassisControl() |
| 69 | intf.powerOff() |
| 70 | elif (cmd == "setsensor"): |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 71 | obj.SetSensor(ipmi_id,dbus.Byte(int(data))) |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 72 | elif (cmd == "getsensors"): |
| 73 | intf_sens = Openbmc.getManagerInterface(bus,"Sensors") |
| 74 | data = intf_sens.getSensors() |
| 75 | prettyPrint(data) |
| 76 | elif (cmd == "updatefru"): |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 77 | d = { 'manufacturer' : data } |
| 78 | obj.UpdateFru(ipmi_id,d) |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 79 | elif (cmd == "getfrus"): |
| 80 | intf_fru = Openbmc.getManagerInterface(bus,"Inventory") |
| 81 | data = intf_fru.getFrus() |
| 82 | prettyPrint(data) |
| 83 | elif (cmd == "pokewatchdog"): |
| 84 | intf = self.getWatchdog() |
| 85 | intf.poke() |
| 86 | elif (cmd == "statewatchdog"): |
| 87 | intf = self.getWatchdog() |
| 88 | intf.start() |
| 89 | else: |
| 90 | print "Unsupported command" |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |