def run(self):
        from app import APP
        APP.Functions.set_process_name ( "0@TFTPD_DATA" )
        logger = APP.LoggingClient ( name = "TFTPD%05d" % self.pid )
        queue_errors = 0
        while 1:
            try:
                (client_address, initiating_packet, filename, filesize) = self.rfQueue.get()
            except:
                queue_errors += 1
                if queue_errors > 2:
                    logger ("Too many errors reading rfqueue")
                    break
                time.sleep(queue_errors)
            
            queue_errors = 0
            if client_address is None: break
            logger ("Sending %s to %s" % (filename, client_address))
            try:
                with open(filename, 'r') as source:
                    try:
                        (bytes, dt, speed) = Protocol.Handle_RRQ (initiating_packet, client_address, source)
                        logger ( "Sent %d bytes to %s at %.1f kB/s" % (bytes, client_address, speed/ 1024) )
                    except Protocol.TFTPProtocolError as e:
                        logger ( "TFTP Protocol Error: %s" %  e )
            except:
                info = sys.exc_info()[:2]
                logger ( "TFTP error: %s, %s" % (info[0], info[1]))                

        logger ( "EXIT" )
    def run(self):
        from app import APP
        APP.Functions.set_process_name ( "0@TFTPD" )        
        logger = APP.LoggingClient ( name="TFTPD" )
        
        controller = APP.Controller( APP.BE.CONTROLLER.tftpd )
        
        logger ( "Initializing the server." )
        server_process = Process ( name="TFTPD_LISTEN", target=ProvisioningTFTPServer )
        server_process.start()
        
        while True:
            action = APP.ControllerWait ( controller )
            if action == "STOP": break
        
        logger ("Terminating the server.")
        os.kill ( server_process.pid, signal.SIGHUP )        
        logger ("Waiting for all children to exit.")                
        server_process.join()
        logger ( "Finished." )
            
#config = ProvCon.Configuration()
#TFTPD = pcTFTPD()
#time.sleep(2)
#ProvCon.ControllerAction ( config.get ( "CONTROLLER", "tftpd"), "STOP" )
#TFTPD.join()
 def __init__(self):
     from app import APP
     Server.BaseTFTPServer.__init__(self)
     APP.Functions.set_process_name ( "0@TFTPD_LISTEN" )
     
     self.logger = APP.LoggingClient ( name="TFTPD_SRV" )
     #The queue for "ready-to-be-sent" files
     self.rfQueue = Queue(2048)
     
     #The base oven & cook - simple TFTP
     base_oven = FileOven ( root = APP.BE.TFTP.dir, name="FILES" )
     self.logger ( "Setting up %s." % base_oven )
     base_queue_size =  APP.BE.TFTP._i_queue_size
     base_cook_queue = Queue(base_queue_size)
     
     #The cook for cm firmware files
     cm_fw_oven = FileOven ( root = APP.BE.DOCSIS.fwdir, name="CM FW" )
     self.logger ( "Setting up %s." % cm_fw_oven )
     cm_fw_oven.deny ( (0,0) )
     cm_fw_queue = Queue(16)
     
     #The cook for cm config files
     cm_cfg_oven = CableModemConfigOven ( root = APP.BE.DOCSIS.dir, name="CM CONFIG" )
     self.logger ( "Setting up %s." % cm_cfg_oven )        
     cm_cfg_oven.deny ( (0,0) )
     cm_cfg_queue_size = APP.BE.DOCSIS._i_tftp_queue_size
     cm_cfg_queue = Queue (cm_cfg_queue_size)
     
     #The sub-processes count
     base_cooks_count = APP.BE.TFTP._i_cooks
     cm_fw_cooks_count = APP.BE.DOCSIS._i_tftp_cm_fw_cooks
     cm_cfg_cooks_count = APP.BE.DOCSIS._i_tftp_cm_cfg_cooks
     
     self.cooks = [ 
         (cm_cfg_oven, cm_cfg_queue, [CableModemConfigCook(cm_cfg_queue, self.rfQueue, cm_cfg_oven) for i in range(0,cm_cfg_cooks_count)]),
         (cm_fw_oven, cm_fw_queue, [FileCook(cm_fw_queue, self.rfQueue, cm_fw_oven) for i in range(0,cm_fw_cooks_count)] ),
         (base_oven, base_cook_queue, [FileCook(base_cook_queue, self.rfQueue, base_oven) for i in range(0,base_cooks_count)]),             
                  ]
     self.logger ( "Starting the cooks." )
     #run cooks, run!
     for (_,_,cooklist) in self.cooks:
         for cook in cooklist: cook.start()
     
     data_senders_count = APP.BE.TFTP._i_senders
     self.data_senders = [ TFTPDataSender (self.rfQueue)  for i in range(0,data_senders_count) ]
     for sender in self.data_senders: sender.start()
     
     signal.signal ( signal.SIGHUP, self.shutdown )        
     self.on = True
     #self.timeout = 4
     error_count = 0
     while self.on:   
         try:
             self.handle_request()
         except Exception as e:                
             error_count += 1
             self.logger ( "error#%d in handle_request (%s)" % (error_count, e) )
             if error_count > 10: break
     self.logger ( "TFTP service no longer active." )
Exemple #4
0
 def __init__(self):
     from app import APP
     self.logger = APP.LoggingClient(name="UIHUB")
     addr = APP.Functions.parse_socket_address(APP.BE.CLI.server_address)
     try:
         os.unlink(addr)
     except:
         pass
     self.logger("Starting. Listening on {0}".format(addr))
     Listener.__init__(self, addr)
     self.queue = ThreadingQueue.Queue(1024)
     self.workers = [
         CLIWorker(self.queue, self.logger) for i in range(0, 5)
     ]
Exemple #5
0
    def run(self):

        self.logging_server = APP.LoggingServer()
        self.logger = APP.LoggingClient(name="MAIN")
        logger = self.logger

        logger("-=<" + ("-" * 70) + ">=-")
        logger("Provisioning v0.01, started.")

        self.controllers = {}
        for (cname, cpath) in APP.BE.CONTROLLER:
            self.controllers[cname] = cpath

        self.processes = {}
        self.start_services()
        self.cli = APP.CLIServer()
        self.cli.serve()
        self.exit()
 def run(self):
     from app import APP
     APP.Functions.set_process_name ( "0@TFTPD_FILE" )
     logger = APP.LoggingClient ( name="TFTP_FILE" )
     while True:
         (initiating_packet, client_address) = self.myQueue.get()
         if initiating_packet is None: break
         print "cooking %s" % initiating_packet
         (filename, filesize) = self.oven.prepare (initiating_packet.filename, client_address[0])
         if filesize < 0:
             logger ( "%s, ERROR, %s" % (client_address[0], filename) )
             Protocol.Send_ERROR (client_address, 0, filename)
         else:
             try:
                 self.rfQueue.put ( (client_address, initiating_packet, filename, filesize) )
             except ThreadingQueue.full:
                 logger ( "%s, ERROR, rf queue full" % (client_address[0],) )
                 Protocol.Send_ERROR (client_address, 0, 'rf queue full' )