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 | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 42 | bus = Openbmc.getDBus() |
| 43 | |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 44 | #name = dbus.service.BusName(DBUS_NAME,bus) |
| 45 | #mainloop = gobject.MainLoop() |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 46 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 47 | cmd = sys.argv[1] |
| 48 | data = None |
| 49 | ipmi_id = dbus.Byte(0) |
| 50 | if (len(sys.argv) > 2): |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 51 | ipmi_id = sys.argv[2] |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 52 | if (len(sys.argv)>3): |
| 53 | data = sys.argv[3] |
| 54 | |
| 55 | if (cmd == "poweron"): |
| 56 | intf = getChassisControl() |
| 57 | intf.powerOn() |
| 58 | elif (cmd == "poweroff"): |
| 59 | intf = getChassisControl() |
| 60 | intf.powerOff() |
| 61 | elif (cmd == "setsensor"): |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 62 | intf_sys = Openbmc.getManagerInterface(bus,"System") |
| 63 | obj_info = intf_sys.getObjectFromId("SENSOR",ipmi_id) |
| 64 | obj_path = obj_info['obj_path'] |
| 65 | bus_name = obj_info['bus_name'] |
| 66 | if (obj_path != "" and bus_name != ""): |
| 67 | obj = bus.get_object(bus_name,obj_path) |
| 68 | intf = dbus.Interface(obj,SENSOR_INTERFACE) |
| 69 | intf.setValue(dbus.Byte(int(data))) |
| 70 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 71 | elif (cmd == "getsensors"): |
| 72 | intf_sens = Openbmc.getManagerInterface(bus,"Sensors") |
| 73 | data = intf_sens.getSensors() |
| 74 | prettyPrint(data) |
| 75 | elif (cmd == "updatefru"): |
Norman James | dfdaca9 | 2015-09-27 22:11:15 -0500 | [diff] [blame] | 76 | d = { 'manufacturer' : data } |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 77 | intf_sys = Openbmc.getManagerInterface(bus,"System") |
| 78 | obj_info = intf_sys.getObjectFromId("FRU",ipmi_id) |
| 79 | obj_path = obj_info['obj_path'] |
| 80 | bus_name = obj_info['bus_name'] |
| 81 | if (obj_path != "" and bus_name != ""): |
| 82 | obj = bus.get_object(bus_name,obj_path) |
| 83 | intf = dbus.Interface(obj,"org.openbmc.InventoryItem") |
| 84 | intf.update(d) |
| 85 | |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 86 | elif (cmd == "getfrus"): |
| 87 | intf_fru = Openbmc.getManagerInterface(bus,"Inventory") |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 88 | data = intf_fru.getItems() |
| 89 | for i in data: |
| 90 | for k in data[i].keys(): |
| 91 | print k+" = "+str(data[i][k]) |
Norman James | 31cda68 | 2015-10-06 16:52:43 -0500 | [diff] [blame] | 92 | elif (cmd == "updatefw"): |
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 93 | obj = bus.get_object('org.openbmc.flash.Bios','/org/openbmc/flash/Bios_0') |
| 94 | intf = dbus.Interface(obj,"org.openbmc.Flash") |
| 95 | intf.updateViaTftp("bakerstreet.aus.stglabs.ibm.com","firmware.bin") |
Norman James | 31cda68 | 2015-10-06 16:52:43 -0500 | [diff] [blame] | 96 | elif (cmd == "fwstatus"): |
| 97 | intf = Openbmc.getManagerInterface(bus,"Flash") |
| 98 | status = intf.getStatus() |
| 99 | for i in status: |
| 100 | print i+" = "+status[i] |
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 101 | elif (cmd == "pokewatchdog"): |
| 102 | intf = self.getWatchdog() |
| 103 | intf.poke() |
| 104 | elif (cmd == "statewatchdog"): |
| 105 | intf = self.getWatchdog() |
| 106 | intf.start() |
| 107 | else: |
| 108 | print "Unsupported command" |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |