Norman James | 372b966 | 2015-10-06 07:47:55 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import gobject |
| 5 | import dbus |
| 6 | import dbus.service |
| 7 | import dbus.mainloop.glib |
| 8 | import tftpy |
| 9 | |
| 10 | |
| 11 | |
| 12 | DBUS_NAME = 'org.openbmc.managers.Flash' |
| 13 | OBJ_NAME = '/org/openbmc/managers/'+sys.argv[1] |
| 14 | TFTP_PORT = 69 |
| 15 | DOWNLOAD_DIR = '/tmp' |
| 16 | |
| 17 | class FlashManagerObject(dbus.service.Object): |
| 18 | def __init__(self,bus,name): |
| 19 | self.dbus_objects = { } |
| 20 | |
| 21 | dbus.service.Object.__init__(self,bus,name) |
| 22 | ## load utilized objects |
| 23 | self.dbus_objects = { |
| 24 | 'bios' : { |
| 25 | 'bus_name' : 'org.openbmc.flash.Bios', |
| 26 | 'object_name' : '/org/openbmc/flash/Bios_0', |
| 27 | 'interface_name' : 'org.openbmc.Flash' |
| 28 | }, |
| 29 | 'bmc' : { |
| 30 | 'bus_name' : 'org.openbmc.flash.Bmc', |
| 31 | 'object_name' : '/org/openbmc/flash/Bmc_0', |
| 32 | 'interface_name' : 'org.openbmc.Flash' |
| 33 | } |
| 34 | } |
| 35 | bus = dbus.SessionBus() |
| 36 | |
| 37 | def getInterface(self,name): |
| 38 | o = self.dbus_objects[name] |
| 39 | obj = bus.get_object(o['bus_name'],o['object_name']) |
| 40 | return dbus.Interface(obj,o['interface_name']) |
| 41 | |
| 42 | @dbus.service.method(DBUS_NAME, |
| 43 | in_signature='sss', out_signature='') |
| 44 | def updateFromTftp(self,flash,url,filename): |
| 45 | if (self.dbus_objects.has_key(flash) == False): |
| 46 | print "Error: Not a valid flash device: "+flash |
| 47 | return |
| 48 | try: |
| 49 | client = tftpy.TftpClient(url, TFTP_PORT) |
| 50 | outfile = DOWNLOAD_DIR+"/"+filename |
| 51 | client.download(filename,outfile) |
| 52 | intf = self.getInterface(flash) |
| 53 | intf.update(outfile) |
| 54 | |
| 55 | except Exception as e: |
| 56 | print "ERROR: "+str(e) |
| 57 | |
| 58 | |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 62 | |
| 63 | bus = dbus.SessionBus() |
| 64 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 65 | obj = FlashManagerObject(bus, OBJ_NAME) |
| 66 | mainloop = gobject.MainLoop() |
| 67 | |
| 68 | print "Running Flash Manager" |
| 69 | mainloop.run() |
| 70 | |