def handle(self):
     lu.log("Receiveing binary program.")
     fp = tempfile.NamedTemporaryFile()
     data = self.request.recv(1024)
     while data:
         fp.write(data)
         data = self.request.recv(1024)
     lu.log("Finished Receiveing binary program.")
     fp.seek(0)
     fileHash = lu.getHash(fp.name)
     lu.log("Hashed Program : " + fileHash)
     # print(progTable.getTable())
     progEntry = progTable.getProgByHash(fileHash)
     for i in progEntry["nodes"]:
         node=lu.getNodeByName(i)
         lu.sendFile ( fp.name , (node["addr"], int(node["minion_scriptrec"]))) ## SEND DATA TO NODES
     fp.close()
     lu.log("Finished sending binary program.")
Example #2
0
 def handle(self):
     lu.log("Receiveing binary program.")
     fp = tempfile.NamedTemporaryFile()
     data = self.request.recv(1024)
     while data:
         fp.write(data)
         data = self.request.recv(1024)
     lu.log("Finished Receiveing binary program.")
     fp.seek(0)
     fileHash = lu.getHash(fp.name)
     lu.log("Hashed Program : " + fileHash)
     # print(progTable.getTable())
     progEntry = progTable.getProgByHash(fileHash)
     for i in progEntry["nodes"]:
         node = lu.getNodeByName(i)
         lu.sendFile(fp.name, (node["addr"], int(
             node["minion_scriptrec"])))  ## SEND DATA TO NODES
     fp.close()
     lu.log("Finished sending binary program.")
Example #3
0
    def do_POST(self):
        lu.log("Post Request - " + self.path)
        pathroot=self.path.split("/")
        while "" in pathroot:
            pathroot.remove("")
        if(pathroot[0] == lu.paths["alpha_scripts"]): # TEST THIS : This may be broken : file upload
            lu.log("Uploading Script - " + self.path)
            fp=self.rfile
            filePath=re.sub("^/",os.getcwd()+"/",self.path)
            filePath=re.sub("%20"," ",filePath)
            length = int(self.headers.get_all('content-length')[0])
            self.setHeaders(200)
            if(length > 0):
                f = open(filePath, 'wb')
                f.write(fp.read(length))
                f.close()
        elif(self.path == lu.paths["alpha_postScript"]): # post to master
            masterAddr = lu.getAddrOf("Lambda-M")
            if not masterAddr:
                lu.log("Could not get Master Addr.")
                self.setHeaders(500)
            length = int(self.headers.get_all('content-length')[0])
            if(length > 0):
                # send json to master http post
                data = json.loads(self.rfile.read(length).decode("UTF-8"))
                data["FileLoc"]=lu.paths["alpha_scripts"] + "/" + data["script"]
                data["Hash"] = lu.getHash(data["FileLoc"])
                lu.log("Hashed Program : " + data["Hash"])
                lu.postHTTP(json.dumps(data),masterAddr,lu.getPort("Master_JSONpost"),lu.paths["master_postScript"])

                # send binary data to socket
                lu.sendFile(data["FileLoc"],(masterAddr,int(lu.getPort("Master_programRec"))))
                # self.send(data["Hash"])
                self.setHeaders(200)
                self.wfile.write(data["Hash"].encode("UTF-8"))
            else:
                lu.log("Nothing to send to master")
                self.setHeaders(500)
        else:
            lu.log("Could not post " + self.path)