Norman James | 90baede | 2015-09-02 20:32:49 -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 xml.etree.ElementTree as ET |
| 10 | |
| 11 | if (len(sys.argv) < 2): |
| 12 | print "Usage: ipmi_bt.py [system name]" |
| 13 | exit(1) |
| 14 | |
| 15 | System = __import__(sys.argv[1]) |
| 16 | import Openbmc |
| 17 | |
| 18 | DBUS_NAME = 'org.openbmc.control.IpmiBt' |
| 19 | OBJ_NAME = '/org/openbmc/control/IpmiBt' |
| 20 | |
| 21 | class IpmiBt(dbus.service.Object): |
| 22 | def __init__(self,bus,name): |
| 23 | dbus.service.Object.__init__(self,bus,name) |
| 24 | |
| 25 | @dbus.service.signal(DBUS_NAME) |
| 26 | def UpdateFru(self, iid, message): |
| 27 | pass |
| 28 | |
| 29 | @dbus.service.signal(DBUS_NAME) |
| 30 | def UpdateSensor(self, iid, message): |
| 31 | pass |
| 32 | |
| 33 | @dbus.service.method(DBUS_NAME) |
| 34 | def emitUpdateFru(self,ipmi_id,mfg): |
| 35 | data = { |
| 36 | 'manufacturer' : mfg |
| 37 | } |
| 38 | self.UpdateFru(ipmi_id,data) |
| 39 | return 'Signal emitted' |
| 40 | |
| 41 | @dbus.service.method(DBUS_NAME) |
| 42 | def emitUpdateSensor(self,ipmi_id,data): |
| 43 | self.UpdateSensor(ipmi_id,int(data)) |
| 44 | print "update sensor emitted" |
| 45 | return 'Signal emitted' |
| 46 | |
| 47 | def getSensor(self,ipmi_id): |
| 48 | obj = bus.get_object('org.openbmc.managers.IpmiTranslator', |
| 49 | '/org/openbmc/managers/IpmiTranslator/Barreleye') |
| 50 | intf = dbus.Interface(obj, 'org.openbmc.managers.IpmiTranslator' ) |
| 51 | return intf.getSensor(ipmi_id) |
| 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | |
| 56 | cmd = sys.argv[2] |
| 57 | ipmi_id = int(sys.argv[3]) |
| 58 | if (len(sys.argv)>4): |
| 59 | data = sys.argv[4] |
| 60 | |
| 61 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 62 | bus = dbus.SessionBus() |
| 63 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 64 | obj = IpmiBt(bus,OBJ_NAME) |
| 65 | mainloop = gobject.MainLoop() |
| 66 | |
| 67 | if (cmd == 'updatefru'): |
| 68 | obj.emitUpdateFru(ipmi_id,data) |
| 69 | elif (cmd == 'setsensor'): |
| 70 | obj.emitUpdateSensor(ipmi_id,data) |
| 71 | elif (cmd == 'getsensor'): |
| 72 | print obj.getSensor(ipmi_id) |
| 73 | |
| 74 | |
| 75 | #mainloop.run() |
| 76 | |