blob: 9dd6c2d5cd4ea3ed925224db28bbbd691c1b5db5 [file] [log] [blame]
Norman James42c1be82015-10-22 14:34:26 -05001#!/usr/bin/python -u
Norman Jamesf066e872015-10-07 15:29:51 -05002
3import sys
4import gobject
5import dbus
6import dbus.service
7import dbus.mainloop.glib
Norman James0b73e7d2016-01-19 14:03:50 -06008import subprocess
Brad Bishop84e73b52016-05-12 15:57:52 -04009from obmc.dbuslib.bindings import get_dbus
Brad Bishop0b380f72016-06-10 00:29:50 -040010import obmc_system_config as System
Norman Jamesf066e872015-10-07 15:29:51 -050011
12
13DBUS_NAME = 'org.openbmc.managers.Download'
14OBJ_NAME = '/org/openbmc/managers/Download'
15TFTP_PORT = 69
Norman Jamesf066e872015-10-07 15:29:51 -050016
17class DownloadManagerObject(dbus.service.Object):
18 def __init__(self,bus,name):
19 dbus.service.Object.__init__(self,bus,name)
Norman Jamesf066e872015-10-07 15:29:51 -050020 bus.add_signal_receiver(self.DownloadHandler,
Norman James8585b212016-01-29 08:08:30 -060021 dbus_interface = "org.openbmc.Flash",
22 signal_name = "Download", path_keyword = "path")
23 bus.add_signal_receiver(self.TftpDownloadHandler,
24 signal_name = "TftpDownload", path_keyword = "path")
25
Norman Jamesf066e872015-10-07 15:29:51 -050026
Norman James18998182015-10-11 21:54:53 -050027 @dbus.service.signal(DBUS_NAME,signature='ss')
28 def DownloadComplete(self,outfile,filename):
Norman Jamesf066e872015-10-07 15:29:51 -050029 print "Download Complete: "+outfile
30 return outfile
31
Norman James18998182015-10-11 21:54:53 -050032 @dbus.service.signal(DBUS_NAME,signature='s')
33 def DownloadError(self,filename):
Norman Jamesf066e872015-10-07 15:29:51 -050034 pass
35
Norman James8585b212016-01-29 08:08:30 -060036 def TftpDownloadHandler(self,ip,filename,path = None):
37 try:
38 filename = str(filename)
39 print "Downloading: "+filename+" from "+ip
40 outfile = System.FLASH_DOWNLOAD_PATH+"/"+filename
41 rc = subprocess.call(["tftp", "-l",outfile,"-r",filename,"-g",ip])
42 if (rc == 0):
43 self.DownloadComplete(outfile,filename)
44 else:
45 self.DownloadError(filename)
46
47
48 except Exception as e:
49 print "ERROR DownloadManager: "+str(e)
50 self.DownloadError(filename)
51
52
53 ## TODO: this needs to be deprecated. Shouldn't call flash interface from here
Norman James166acf42015-10-22 07:11:51 -050054 def DownloadHandler(self,url,filename,path = None):
Norman Jamesf066e872015-10-07 15:29:51 -050055 try:
56 filename = str(filename)
Norman Jamesf066e872015-10-07 15:29:51 -050057 print "Downloading: "+filename+" from "+url
Norman James408920d2015-10-08 07:02:45 -050058 outfile = System.FLASH_DOWNLOAD_PATH+"/"+filename
Norman James8af7d4a2016-01-06 14:09:08 -060059 subprocess.call(["tftp", "-l",outfile,"-r",filename,"-g",url])
Norman James166acf42015-10-22 07:11:51 -050060 obj = bus.get_object("org.openbmc.control.Flash",path)
61 intf = dbus.Interface(obj,"org.openbmc.Flash")
62 intf.update(outfile)
Norman James8af7d4a2016-01-06 14:09:08 -060063
Norman Jamesf066e872015-10-07 15:29:51 -050064 except Exception as e:
65 print "ERROR DownloadManager: "+str(e)
Norman James166acf42015-10-22 07:11:51 -050066 obj = bus.get_object("org.openbmc.control.Flash",path)
67 intf = dbus.Interface(obj,"org.openbmc.Flash")
68 intf.error("Download Error: "+filename)
Norman Jamesf066e872015-10-07 15:29:51 -050069
70
71if __name__ == '__main__':
72 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Brad Bishop84e73b52016-05-12 15:57:52 -040073 bus = get_dbus()
Norman Jamesf066e872015-10-07 15:29:51 -050074 name = dbus.service.BusName(DBUS_NAME, bus)
75 obj = DownloadManagerObject(bus, OBJ_NAME)
76 mainloop = gobject.MainLoop()
77
78 print "Running Download Manager"
79 mainloop.run()
80