Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import subprocess |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 5 | #from gi.repository import GObject |
| 6 | import gobject |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 7 | import dbus |
| 8 | import dbus.service |
| 9 | import dbus.mainloop.glib |
| 10 | import PropertyManager |
| 11 | |
| 12 | if (len(sys.argv) < 2): |
| 13 | print "Usage: ipmi_manager.py [system name]" |
| 14 | exit(1) |
| 15 | |
| 16 | System = __import__(sys.argv[1]) |
| 17 | import Openbmc |
| 18 | |
| 19 | DBUS_NAME = 'org.openbmc.managers.Ipmi' |
| 20 | OBJ_NAME = '/org/openbmc/managers/Ipmi' |
| 21 | |
| 22 | |
| 23 | class IpmiManager(dbus.service.Object): |
| 24 | def __init__(self,bus,name): |
| 25 | dbus.service.Object.__init__(self,bus,name) |
| 26 | |
| 27 | ## IPMI commands |
| 28 | @dbus.service.method(DBUS_NAME, |
| 29 | in_signature='yv', out_signature='') |
| 30 | def setSensor(self,sensor_id,value): |
| 31 | intf_sens = Openbmc.getManagerInterface(bus,"Sensors") |
| 32 | intf_sens.setSensorFromId(sensor_id,value) |
| 33 | |
| 34 | @dbus.service.method(DBUS_NAME, |
| 35 | in_signature='y', out_signature='v') |
| 36 | def getSensor(self,sensor_id): |
| 37 | intf_sens = Openbmc.getManagerInterface(bus,"Sensors") |
| 38 | return intf_sens.getSensorFromId(sensor_id) |
| 39 | |
| 40 | @dbus.service.method(DBUS_NAME, |
| 41 | in_signature='ia{sv}', out_signature='') |
| 42 | def updateFru(self,fru_id,data): |
| 43 | intf_fru = Openbmc.getManagerInterface(bus,"Frus") |
| 44 | intf_fru.updateFru(fru_id,data) |
| 45 | |
| 46 | @dbus.service.method(DBUS_NAME, |
| 47 | in_signature='', out_signature='s') |
| 48 | def getFrus(self): |
| 49 | intf_fru = Openbmc.getManagerInterface(bus,"Frus") |
| 50 | return intf_fru.getFrus() |
| 51 | |
| 52 | |
| 53 | @dbus.service.method(DBUS_NAME, |
| 54 | in_signature='', out_signature='') |
| 55 | def pokeHostWatchdog(self): |
| 56 | ## TODO don't do hardcoding |
| 57 | obj = bus.get_object('org.openbmc.watchdog.Host', |
| 58 | '/org/openbmc/watchdog/HostWatchdog_0') |
| 59 | intf = dbus.Interface(obj, 'org.openbmc.Watchdog' ) |
| 60 | intf.poke() |
| 61 | return None |
| 62 | |
| 63 | @dbus.service.method(DBUS_NAME, |
| 64 | in_signature='', out_signature='') |
| 65 | def startHostWatchdog(self): |
| 66 | ## TODO don't do hardcoding |
| 67 | obj = bus.get_object('org.openbmc.watchdog.Host', |
| 68 | '/org/openbmc/watchdog/HostWatchdog_0') |
| 69 | intf = dbus.Interface(obj, 'org.openbmc.Watchdog' ) |
| 70 | intf.start() |
| 71 | return None |
| 72 | |
| 73 | @dbus.service.method(DBUS_NAME, |
| 74 | in_signature='', out_signature='') |
| 75 | def powerOn(self): |
| 76 | ## TODO don't do hardcoding |
| 77 | obj = bus.get_object('org.openbmc.control.Chassis', |
| 78 | '/org/openbmc/control/Chassis') |
| 79 | intf = dbus.Interface(obj, 'org.openbmc.control.Chassis' ) |
| 80 | intf.powerOn() |
| 81 | return None |
| 82 | |
| 83 | @dbus.service.method(DBUS_NAME, |
| 84 | in_signature='', out_signature='') |
| 85 | def powerOff(self): |
| 86 | ## TODO don't do hardcoding |
| 87 | obj = bus.get_object('org.openbmc.control.Chassis', |
| 88 | '/org/openbmc/control/Chassis') |
| 89 | intf = dbus.Interface(obj, 'org.openbmc.control.Chassis' ) |
| 90 | intf.powerOff() |
| 91 | return None |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | if __name__ == '__main__': |
| 97 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 98 | bus = dbus.SessionBus() |
| 99 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 100 | obj = IpmiManager(bus,OBJ_NAME) |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 101 | mainloop = gobject.MainLoop() |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 102 | |
| 103 | print "Running IpmiManager" |
| 104 | mainloop.run() |
| 105 | |