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 | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 13 | SENSOR_INTERFACE = "org.openbmc.SensorValue" |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 14 | |
| 15 | class IpmiBt(dbus.service.Object): |
| 16 | def __init__(self,bus,name): |
| 17 | dbus.service.Object.__init__(self,bus,name) |
| 18 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 19 | |
| 20 | def 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 | |
| 26 | def 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 | |
| 32 | def 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 James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 38 | |
| 39 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 40 | if __name__ == '__main__': |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 41 | #dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 42 | bus = dbus.SessionBus() |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 43 | #name = dbus.service.BusName(DBUS_NAME,bus) |
| 44 | #mainloop = gobject.MainLoop() |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 45 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 46 | cmd = sys.argv[1] |
| 47 | data = None |
| 48 | ipmi_id = dbus.Byte(0) |
| 49 | if (len(sys.argv) > 2): |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 50 | ipmi_id = sys.argv[2] |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 51 | 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 James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 61 | 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 James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 70 | elif (cmd == "getsensors"): |
| 71 | intf_sens = Openbmc.getManagerInterface(bus,"Sensors") |
| 72 | data = intf_sens.getSensors() |
| 73 | prettyPrint(data) |
| 74 | elif (cmd == "updatefru"): |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 75 | d = { 'manufacturer' : data } |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 76 | 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 James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 85 | elif (cmd == "getfrus"): |
| 86 | intf_fru = Openbmc.getManagerInterface(bus,"Inventory") |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 87 | data = intf_fru.getItems() |
| 88 | for i in data: |
| 89 | for k in data[i].keys(): |
| 90 | print k+" = "+str(data[i][k]) |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 91 | 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 | |