Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import subprocess |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 5 | import dbus |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 6 | from gi.repository import GObject |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 9 | |
| 10 | if (len(sys.argv) < 2): |
| 11 | print "Usage: ipmi_bt.py [system name]" |
| 12 | exit(1) |
| 13 | |
| 14 | System = __import__(sys.argv[1]) |
| 15 | import Openbmc |
| 16 | |
| 17 | DBUS_NAME = 'org.openbmc.control.IpmiBt' |
| 18 | OBJ_NAME = '/org/openbmc/control/IpmiBt' |
| 19 | |
| 20 | class IpmiBt(dbus.service.Object): |
| 21 | def __init__(self,bus,name): |
| 22 | dbus.service.Object.__init__(self,bus,name) |
| 23 | |
| 24 | @dbus.service.signal(DBUS_NAME) |
| 25 | def UpdateFru(self, iid, message): |
| 26 | pass |
| 27 | |
| 28 | @dbus.service.signal(DBUS_NAME) |
| 29 | def UpdateSensor(self, iid, message): |
| 30 | pass |
| 31 | |
| 32 | @dbus.service.method(DBUS_NAME) |
| 33 | def emitUpdateFru(self,ipmi_id,mfg): |
| 34 | data = { |
| 35 | 'manufacturer' : mfg |
| 36 | } |
| 37 | self.UpdateFru(ipmi_id,data) |
| 38 | return 'Signal emitted' |
| 39 | |
| 40 | @dbus.service.method(DBUS_NAME) |
| 41 | def emitUpdateSensor(self,ipmi_id,data): |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame^] | 42 | self.UpdateSensor(ipmi_id,dbus.Byte(int(data))) |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 43 | print "update sensor emitted" |
| 44 | return 'Signal emitted' |
| 45 | |
| 46 | def getSensor(self,ipmi_id): |
| 47 | obj = bus.get_object('org.openbmc.managers.IpmiTranslator', |
| 48 | '/org/openbmc/managers/IpmiTranslator/Barreleye') |
| 49 | intf = dbus.Interface(obj, 'org.openbmc.managers.IpmiTranslator' ) |
| 50 | return intf.getSensor(ipmi_id) |
| 51 | |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame^] | 52 | def pokeHostWatchdog(self): |
| 53 | obj = bus.get_object('org.openbmc.managers.IpmiTranslator', |
| 54 | '/org/openbmc/managers/IpmiTranslator/Barreleye') |
| 55 | intf = dbus.Interface(obj, 'org.openbmc.managers.IpmiTranslator' ) |
| 56 | intf.pokeHostWatchdog() |
| 57 | |
| 58 | def startHostWatchdog(self): |
| 59 | obj = bus.get_object('org.openbmc.managers.IpmiTranslator', |
| 60 | '/org/openbmc/managers/IpmiTranslator/Barreleye') |
| 61 | intf = dbus.Interface(obj, 'org.openbmc.managers.IpmiTranslator' ) |
| 62 | intf.startHostWatchdog() |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 67 | |
| 68 | if __name__ == '__main__': |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame^] | 69 | |
| 70 | cmd = "" |
| 71 | data = None |
| 72 | ipmi_id = 0 |
| 73 | if (len(sys.argv) > 2): |
| 74 | cmd = sys.argv[2] |
| 75 | if (len(sys.argv) > 3): |
| 76 | ipmi_id = int(sys.argv[3]) |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 77 | if (len(sys.argv)>4): |
| 78 | data = sys.argv[4] |
| 79 | |
| 80 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 81 | bus = dbus.SessionBus() |
| 82 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 83 | obj = IpmiBt(bus,OBJ_NAME) |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 84 | mainloop = GObject.MainLoop() |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 85 | |
| 86 | if (cmd == 'updatefru'): |
| 87 | obj.emitUpdateFru(ipmi_id,data) |
| 88 | elif (cmd == 'setsensor'): |
| 89 | obj.emitUpdateSensor(ipmi_id,data) |
| 90 | elif (cmd == 'getsensor'): |
| 91 | print obj.getSensor(ipmi_id) |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame^] | 92 | elif (cmd == 'pokewatchdog'): |
| 93 | print obj.pokeHostWatchdog() |
| 94 | elif (cmd == 'startwatchdog'): |
| 95 | print obj.startHostWatchdog() |
| 96 | else: |
| 97 | print "ERROR: Invalid command" |
| 98 | print "Valid commands: updatefru, setsensor, getsensor, startwatchdog, pokewatchdog" |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 99 | |
| 100 | #mainloop.run() |
| 101 | |