def main(): # make network Table global table table = networkTable() # get messages over UDP to update networkTable tableRequestObj = tableRequest() broadcastListener = OmegaNodeDiscovery( "omega", ("omega_tableReq", tableRequestObj.port)) # get UDP pings from network to create Network table entries lu.log("Getting UDP network pings on : " + str(broadcastListener.broadcastAddr) + ", from port : " + str(lu.getPort("OmegaListen"))) lu.log("Initialized") output = 5 outputCount = 0 while broadcastListener.alive: table.updateEntry(json.dumps(broadcastListener.jsonInfo)) msg = broadcastListener.getMsg() if msg: table.updateEntry(msg) else: outputCount = outputCount + 1 if (outputCount > output): outputCount = 0 print(table.getTable()) time.sleep(1)
def main(): global progTable lu.log("Starting Master.") progTable = ProgTable() master = Master() broadcastListener = lu.nodeDiscovery("Lambda-M", master.getPorts()) lu.log("Initialized")
def execute(self, command): lu.log("Executing : " + command) self.status = 0 self.proc = subP.Popen(shlex.split(command), cwd=os.path.dirname(self.filePath), universal_newlines=True, stdout=subP.PIPE, stderr=subP.PIPE) self.pollSubProc()
def do_GET(self): # check if contained to directory lu.log("Handling the Request to : " + self.path) if(self.path == lu.paths["omega_Table"]): self.setHeaders(200) self.wfile.write(table.getTable().encode("UTF-8")) elif(self.path == lu.paths["omega_MinionTable"]): self.setHeaders(200) self.wfile.write(str(table.getMinionNumber()).encode("UTF-8")) else: self.setHeaders(500)
def do_GET(self): # check if contained to directory lu.log("Handling the Request to : " + self.path) if (self.path == lu.paths["omega_Table"]): self.setHeaders(200) self.wfile.write(table.getTable().encode("UTF-8")) elif (self.path == lu.paths["omega_MinionTable"]): self.setHeaders(200) self.wfile.write(str(table.getMinionNumber()).encode("UTF-8")) else: self.setHeaders(500)
def _broadcast(self, port): # continually sends out ping messages with omega ip addr and name. UDP msg=str(self.addr)+" "+str(self.jsonInfo["omega_tablereq"]) lu.log("Broadcasting omega address on : " + str(lu.getPort("OmegaBroadcast")) ) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) while self.alive: #lu.log("Broadcasting omega address on : " + str(lu.getPort("OmegaBroadcast"]) ) sock.sendto(msg.encode("UTF-8"), (lu.getBroadcast(), lu.getPort("OmegaBroadcast"))) time.sleep(1)
def __init__(self): socketserver.TCPServer.allow_reuse_address = True tableRequestServer = socketserver.TCPServer( (lu.getAddr(), 0), tableRequestHandler) # HTTP broadcastThread = threading.Thread( target=self._threadServe, args=(tableRequestServer, )).start() # serve HTTP in thread self.port = tableRequestServer.server_address[1] lu.log("Serving HTTP Get Table Requests @ " + str(lu.getAddr()) + ":" + str(self.port))
def do_POST(self): lu.log("Handling the Post to : " + self.path) if(self.path == lu.paths["master_postScript"]): length = self.headers['content-length'] # parse data to json data = self.rfile.read(int(length)).decode("UTF-8") progTable.updateEntry(data) self.setHeaders(200) else: self.setHeaders(500)
def do_POST(self): lu.log("Handling the Post to : " + self.path) if (self.path == lu.paths["master_postScript"]): length = self.headers['content-length'] # parse data to json data = self.rfile.read(int(length)).decode("UTF-8") progTable.updateEntry(data) self.setHeaders(200) else: self.setHeaders(500)
def deltaStart(): command = "bash bin/elasticsearch --network.host " + addr with subP.Popen( shlex.split(command), cwd=databaseDir, stdout=subP.PIPE, stderr=subP.PIPE, universal_newlines=True ) as proc: for line in proc.stdout: print(line, end="") for line in proc.stderr: print(line, end="") time.sleep(1) lu.log("Delta Terminated.")
def _listen(self): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((self.addr, lu.getPort("OmegaListen"))) # UDP lu.log("Binded and listening on " + str((self.addr, lu.getPort("OmegaListen")))) while self.alive: data, addr = sock.recvfrom(1024) time.sleep(.1) if not self.readBuffer.full(): self.readBuffer.put(data.decode("UTF-8")) else: self.readBuffer.get() lu.log("Queue overflow. Dropping datagram.")
def main(): checkDependencies("unzip") # make a friendly minion to work for you myMinion = Minion() global minionID minionID = myMinion.ID lu.log(myMinion) # start broadcasting his address while ( not myMinion.getPorts()[0][1] ): time.sleep(.5) broadcaster = lu.nodeDiscovery("Lambda-m." + myMinion.ID, myMinion.getPorts() ) lu.log("Initialized")
def _broadcast(self, port): # continually sends out ping messages with omega ip addr and name. UDP msg = str(self.addr) + " " + str(self.jsonInfo["omega_tablereq"]) lu.log("Broadcasting omega address on : " + str(lu.getPort("OmegaBroadcast"))) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) while self.alive: #lu.log("Broadcasting omega address on : " + str(lu.getPort("OmegaBroadcast"]) ) sock.sendto(msg.encode("UTF-8"), (lu.getBroadcast(), lu.getPort("OmegaBroadcast"))) time.sleep(1)
def main(): checkDependencies("unzip") # make a friendly minion to work for you myMinion = Minion() global minionID minionID = myMinion.ID lu.log(myMinion) # start broadcasting his address while (not myMinion.getPorts()[0][1]): time.sleep(.5) broadcaster = lu.nodeDiscovery("Lambda-m." + myMinion.ID, myMinion.getPorts()) lu.log("Initialized")
def deltaStart(): command = "bash bin/elasticsearch --network.host " + addr with subP.Popen(shlex.split(command), cwd=databaseDir, stdout=subP.PIPE, stderr=subP.PIPE, universal_newlines=True) as proc: for line in proc.stdout: print(line, end='') for line in proc.stderr: print(line, end='') time.sleep(1) lu.log("Delta Terminated.")
def main(): global termEmulator components = ["alpha", "lambda-M", "lambda-m", "omega", "delta"] setup = [] error = [] for arg in compList: arg = re.sub("[^a-zA-Z0-9\-]", "", arg) # remove any none num or alpha char if arg in components: setup.append(arg) else: error.append(arg) if len(setup) == 0 or len(error) > 0: lu.error( "Please specify a list of valid components to start.\n\tValid componenets : " + str(components) + "\n\tYou specified : " + str(sys.argv[1:]) + "\n\tThe following are invalid : " + str(error)) choice = "" if skipVerification == 0: choice = input("Do you want to setup " + str(setup) + " on this node? Y/n: ") choice = re.sub("[^a-zA-Z0-9]", "", choice) # remove any none num or alpha char liveComp = [] if (choice == "" or choice == "y" or choice == "Y"): for comp in setup: liveComp.append(component(comp)) else: lu.error("You've Chosen not to continue.") someAlive = 1 try: while someAlive > 0: someAlive = 0 for comp in liveComp: out = comp.getOutput() if out[0]: sys.stdout.write(out[0] + "\n") sys.stdout.flush() if out[1]: sys.stderr.write(out[1] + "\n") sys.stderr.flush() for comp in liveComp: if comp.isAlive() != None: someAlive = someAlive + comp.isAlive() else: someAlive = 1 except KeyboardInterrupt: for comp in liveComp: lu.log("Killing Process - " + str(comp.subProc.pid)) comp.kill()
def do_GET(self): lu.log("Handling the Request to : " + self.path) if(self.path == "/"): self.setHeaders(200) self.wfile.write(str("Please Request a proper path. Try : "+self.properPath).encode("UTF-8")) elif(self.path == lu.paths["master_ClusterStat"]): self.setHeaders(200) # !!! Gather minion statistics and send to requester !!! self.wfile.write(str("Still need to implement").encode("UTF-8")) elif(self.path == lu.paths["master_progTable"]): self.setHeaders(200) self.wfile.write(str(progTable.getTable()).encode("UTF-8")) else: self.setHeaders(500)
def handle(self): lu.log("Receiving binary program.") try: folder = tempfile.mkdtemp() fp = open(tempfile.mkstemp(dir=folder)[1], 'wb') data = self.request.recv(1024) while data: fp.write(data) data = self.request.recv(1024) fp.seek(0) fileHash = lu.getHash(fp.name) lu.log("Finished Receiveing binary program. Hash : " + fileHash) fileExecuter = Executer(fp.name, fileHash, folder) finally: fp.close()
def do_GET(self): lu.log("Handling the Request to : " + self.path) if (self.path == "/"): self.setHeaders(200) self.wfile.write( str("Please Request a proper path. Try : " + self.properPath).encode("UTF-8")) elif (self.path == lu.paths["master_ClusterStat"]): self.setHeaders(200) # !!! Gather minion statistics and send to requester !!! self.wfile.write(str("Still need to implement").encode("UTF-8")) elif (self.path == lu.paths["master_progTable"]): self.setHeaders(200) self.wfile.write(str(progTable.getTable()).encode("UTF-8")) else: self.setHeaders(500)
def pollSubProc(self): global minionID stdout = ["stdout", self.fileHash, str(minionID)] # location array passed to deltaPostData stderr = ["stderr", self.fileHash, str(minionID)] metaInfo = ["meta", self.fileHash, str(minionID)] # describes lines of output stdoutUpdate = ["stdout", self.fileHash, str(minionID), "_update"] stderrUpdate = ["stderr", self.fileHash, str(minionID), "_update"] stdIndex = 1 # stdout index tracker errIndex = 1 # stderr index tracker # init table data = {int(0): ""} lu.deltaPostData(data, stdout) lu.deltaPostData(data, stderr) lu.deltaPostData(data, metaInfo) while self.proc.poll() == None: # While process is running stdLine = None stdLine = self.proc.stdout.readline() # stdout if stdLine: data = {"doc": {int(stdIndex): str(stdLine)}} lu.deltaPostData(data, stdoutUpdate) stdIndex += 1 errLine = None errLine = self.proc.stderr.readline() # stderr if errLine: data = {"doc": {int(errIndex): str(errLine)}} lu.deltaPostData(data, stderrUpdate) errIndex += 1 if not stdLine and not errLine: # sleep if no output from either time.sleep(1) # get final output after proc ends for line in self.proc.stdout: # stdout data = {"doc": {int(stdIndex): str(line)}} lu.deltaPostData(data, stdoutUpdate) stdIndex += 1 for line in self.proc.stderr: # stderr data = {"doc": {int(errIndex): str(line)}} lu.deltaPostData(data, stderrUpdate) errIndex += 1 # update status self.status = self.proc.poll() lu.log("Executer Finished with status : " + str(self.status)) # Update Meta Info data = {"std": stdIndex, "err": errIndex, "code": self.status} lu.deltaPostData(data, metaInfo)
def main(): global termEmulator components=["alpha","lambda-M","lambda-m","omega","delta"] setup=[] error=[] for arg in compList: arg=re.sub("[^a-zA-Z0-9\-]", "", arg) # remove any none num or alpha char if arg in components: setup.append(arg) else: error.append(arg) if len(setup) == 0 or len(error) > 0: lu.error("Please specify a list of valid components to start.\n\tValid componenets : " + str(components) + "\n\tYou specified : " + str(sys.argv[1:]) + "\n\tThe following are invalid : " + str(error)) choice="" if skipVerification == 0 : choice = input("Do you want to setup " + str(setup) + " on this node? Y/n: ") choice=re.sub("[^a-zA-Z0-9]", "", choice) # remove any none num or alpha char liveComp=[] if(choice == "" or choice == "y" or choice == "Y"): for comp in setup: liveComp.append(component(comp)) else: lu.error("You've Chosen not to continue.") someAlive=1 try: while someAlive > 0: someAlive=0 for comp in liveComp: out = comp.getOutput() if out[0]: sys.stdout.write(out[0]+"\n") sys.stdout.flush() if out[1]: sys.stderr.write(out[1]+"\n") sys.stderr.flush() for comp in liveComp: if comp.isAlive() != None: someAlive=someAlive+comp.isAlive() else: someAlive=1 except KeyboardInterrupt: for comp in liveComp: lu.log("Killing Process - " + str(comp.subProc.pid)) comp.kill()
def component(comp): if(dockerMode): lu.log("Docker Mode is not currently implemented.") else: compPath=os.path.join(DIR, comp) if comp == "alpha": return lu.subProc("./alpha/Alpha-Server.py") elif comp == "lambda-M": return lu.subProc("./lambda-M/LambdaMaster-Server.py") elif comp == "lambda-m": return lu.subProc("./lambda-m/LambdaMinion-Server.py") elif comp == "omega": return lu.subProc("./omega/Omega-Server.py") elif comp == "delta": return lu.subProc("./delta/Delta-Database.py") else: lu.error(comp + " not a recognized component")
def component(comp): if (dockerMode): lu.log("Docker Mode is not currently implemented.") else: compPath = os.path.join(DIR, comp) if comp == "alpha": return lu.subProc("./alpha/Alpha-Server.py") elif comp == "lambda-M": return lu.subProc("./lambda-M/LambdaMaster-Server.py") elif comp == "lambda-m": return lu.subProc("./lambda-m/LambdaMinion-Server.py") elif comp == "omega": return lu.subProc("./omega/Omega-Server.py") elif comp == "delta": return lu.subProc("./delta/Delta-Database.py") else: lu.error(comp + " not a recognized component")
def do_GET(self): # check if contained to directory lu.log("Get Request - " + self.path) filePath=re.sub("^/",os.getcwd()+"/",self.path) filePath=re.sub("%20"," ",filePath) filePath=re.sub("/+","/",filePath) pathSplit=[x for x in self.path.split("/") if x] # TODO : Restructure get using pathSplit # Get listing of nodes from omega. Returns JSON if (self.path == lu.paths["alpha_nodeListing"]): # node requestURL='http://'+str(lu.getOmegaAddr())+':'+str(lu.getPort("omega_tableReq"))+lu.paths["omega_Table"] lu.log("Requesting " + requestURL) msg=None try: with urllib.request.urlopen(requestURL) as response: self.setHeaders(200) try: msg = response.read().decode("UTF-8") self.wfile.write(msg.encode("UTF-8")) except: lu.error("Could not parse routing table") return 1 except: lu.log("Could not get network table from Omega.") # is file or directory reference elif os.path.isfile(filePath): self.setHeaders(200) self.writeFileToHandler(filePath) elif os.path.isdir(filePath): index=os.path.join(filePath,"index.html") if os.path.isfile(index): self.setHeaders(200) self.writeFileToHandler(index) else: if(len(os.listdir(filePath))): for i in os.listdir(filePath): i = "<a href=\'" + self.path + "/" + i + "\'>"+i+"</a></br>" self.wfile.write(i.encode("UTF-8")) else: self.wfile.write("directory empty".encode("UTF-8")) # get database entries for user elif pathSplit[0] == lu.paths["alpha_stdout"] or pathSplit[0] == lu.paths["alpha_stderr"]: msg = lu.deltaGetData(pathSplit) if(not msg): self.setHeaders(500) return self.setHeaders(200) self.wfile.write(msg.encode("UTF-8")) # no file could be found elif not os.path.exists(filePath): self.setHeaders(404) string="File : '" + filePath + "' not found." lu.log(string) self.wfile.write(string.encode("UTF-8")) else: self.setHeaders(500)
def pollSubProc(self): global minionID stdout=["stdout", self.fileHash, str(minionID)] # location array passed to deltaPostData stderr=["stderr", self.fileHash, str(minionID)] metaInfo=["meta", self.fileHash, str(minionID)] # describes lines of output stdoutUpdate=["stdout", self.fileHash, str(minionID), "_update"] stderrUpdate=["stderr", self.fileHash, str(minionID), "_update"] stdIndex=1 # stdout index tracker errIndex=1 # stderr index tracker # init table data={int(0):""} lu.deltaPostData(data, stdout) lu.deltaPostData(data, stderr) lu.deltaPostData(data, metaInfo) while self.proc.poll() == None: # While process is running stdLine=None stdLine = self.proc.stdout.readline() # stdout if stdLine: data={"doc": {int(stdIndex):str(stdLine) }} lu.deltaPostData(data, stdoutUpdate) stdIndex += 1 errLine=None errLine = self.proc.stderr.readline() # stderr if errLine: data={"doc": {int(errIndex):str(errLine) }} lu.deltaPostData(data, stderrUpdate) errIndex += 1 if not stdLine and not errLine: # sleep if no output from either time.sleep(1) # get final output after proc ends for line in self.proc.stdout: # stdout data={"doc": {int(stdIndex):str(line) }} lu.deltaPostData(data, stdoutUpdate) stdIndex += 1 for line in self.proc.stderr: # stderr data={"doc": {int(errIndex):str(line) }} lu.deltaPostData(data, stderrUpdate) errIndex += 1 # update status self.status=self.proc.poll() lu.log("Executer Finished with status : " + str(self.status)) # Update Meta Info data={"std":stdIndex,"err":errIndex,"code":self.status} lu.deltaPostData(data, metaInfo)
def _executeSetup(self): # ZIP FILE if zipfile.is_zipfile(self.filePath) : ZipFile = zipfile.ZipFile(self.filePath) workingDir=os.path.dirname(self.filePath) subP.Popen(shlex.split("unzip -d " + workingDir + " " +self.filePath)).wait() # python unzip does not preserve file permissions so i must use linux unzip. # ZipFile.extractall(workingDir) # https://bugs.python.org/issue15795 self.status=-2 for root, dirs, files in os.walk(workingDir): for f in files: if re.match("makefile", f ,flags=re.IGNORECASE): self.filePath=os.path.join(root, f) command = "make" self.status=None if self.status == -2: lu.log("Could not find Makefile") # TEXT SCRIPT else: command = "bash " + os.path.basename(self.filePath) self.execute(command) shutil.rmtree(self.folder)
def main(): # make network Table global table table = networkTable() # get messages over UDP to update networkTable tableRequestObj = tableRequest() broadcastListener = OmegaNodeDiscovery("omega", ("omega_tableReq", tableRequestObj.port)) # get UDP pings from network to create Network table entries lu.log("Getting UDP network pings on : " + str(broadcastListener.broadcastAddr) + ", from port : " + str(lu.getPort("OmegaListen"))) lu.log("Initialized") output=5 outputCount=0 while broadcastListener.alive: table.updateEntry(json.dumps(broadcastListener.jsonInfo)) msg = broadcastListener.getMsg() if msg: table.updateEntry(msg) else: outputCount = outputCount + 1 if (outputCount > output): outputCount = 0 print(table.getTable()) time.sleep(1)
def _executeSetup(self): # ZIP FILE if zipfile.is_zipfile(self.filePath): ZipFile = zipfile.ZipFile(self.filePath) workingDir = os.path.dirname(self.filePath) subP.Popen( shlex.split("unzip -d " + workingDir + " " + self.filePath) ).wait( ) # python unzip does not preserve file permissions so i must use linux unzip. # ZipFile.extractall(workingDir) # https://bugs.python.org/issue15795 self.status = -2 for root, dirs, files in os.walk(workingDir): for f in files: if re.match("makefile", f, flags=re.IGNORECASE): self.filePath = os.path.join(root, f) command = "make" self.status = None if self.status == -2: lu.log("Could not find Makefile") # TEXT SCRIPT else: command = "bash " + os.path.basename(self.filePath) self.execute(command) shutil.rmtree(self.folder)
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.")
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.")
def updateEntry(self, entry): # print(self.getTable()) try : entry = json.loads(entry) except : lu.log("Failed to load json into prog table") return 1 for i in self.table: if(i["Hash"] == entry["Hash"]): self.table.remove(i) lu.log("deleted table entry") self.table.append(entry) # append to table if entity does not exist lu.log("Added table entry") return 0
def updateEntry(self, entry): # print(self.getTable()) try: entry = json.loads(entry) except: lu.log("Failed to load json into prog table") return 1 for i in self.table: if (i["Hash"] == entry["Hash"]): self.table.remove(i) lu.log("deleted table entry") self.table.append(entry) # append to table if entity does not exist lu.log("Added table entry") return 0
def blockSubProc(command): p = subP.Popen(shlex.split(command)) p.wait() lu.log("Command [" + command + "] Got return code : " + str(p.poll()))
def execute(self, command): lu.log("Executing : " + command) self.status=0 self.proc = subP.Popen(shlex.split(command), cwd=os.path.dirname(self.filePath), universal_newlines=True, stdout=subP.PIPE, stderr=subP.PIPE) self.pollSubProc()
def blockSubProc( command): p = subP.Popen(shlex.split(command)) p.wait() lu.log("Command [" + command + "] Got return code : " + str(p.poll()))
def main(): try: # setup elastic search if not os.path.exists(databaseDir): os.makedirs(databaseDir) req = urllib.request.urlopen(urlToGet) lu.log("Downloading elastic.") with open(outputZip, "wb") as output: while True: data = req.read(4096) if data: output.write(data) else: break lu.log("Unzipping elastic.") with zipfile.ZipFile(outputZip, "r") as zip_ref: zip_ref.extractall(filePath) lu.log("Removing zip file.") os.remove(outputZip) lu.log("Set up elastic successfully.") lu.log("Initialized") lu.log("Starting elastic.") lu.log("=================") deltaStart() except IOError as e: lu.error("Write error", e)
def main(): try: # setup elastic search if not os.path.exists(databaseDir): os.makedirs(databaseDir) req = urllib.request.urlopen(urlToGet) lu.log("Downloading elastic.") with open(outputZip, 'wb') as output: while True: data = req.read(4096) if data: output.write(data) else: break lu.log("Unzipping elastic.") with zipfile.ZipFile(outputZip, "r") as zip_ref: zip_ref.extractall(filePath) lu.log("Removing zip file.") os.remove(outputZip) lu.log("Set up elastic successfully.") lu.log("Initialized") lu.log("Starting elastic.") lu.log("=================") deltaStart() except IOError as e: lu.error("Write error", e)
elif args[i] == "-y": skipVerification = 1 elif args[i] == "-h": print(" " + sys.argv[0] + " <comp1> <comp2> <comp..> <options>") print(" Options:") for i in help: print("\t{:5}{:20}".format(i[0], i[1])) exit(0) else: compList.append(args[i]) i = i + 1 # ========================== # Option Log # ========================== lu.log("Docker Mode Enabled : " + str(bool(dockerMode))) lu.log("Skip Verification messages : " + str(bool(skipVerification))) lu.log("Specified component list : " + str(compList)) # ========================== # Main Method # ========================== def main(): global termEmulator components = ["alpha", "lambda-M", "lambda-m", "omega", "delta"] setup = [] error = [] for arg in compList: arg = re.sub("[^a-zA-Z0-9\-]", "", arg) # remove any none num or alpha char
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)
<meta charset="UTF-8"> <script type="text/javascript"> window.location = " ''' html2=''' "; </script> </head> </html> ''' html = html1 + dest + html2 self.wfile.write(html.encode("UTF-8")) # deletes a script def do_DELETE(self): lu.log("Delete Request - " + self.path) self._setHeaders() self.wfile.write(b"<html><body><h1>delete!</h1></body></html>") # ========================== # Iniitialize # ========================== try: socketserver.TCPServer.allow_reuse_address = True httpd = socketserver.TCPServer((lu.getAddr(), lu.getPort("alpha")), HTTP_webpageHandler) broadcastListener = lu.nodeDiscovery("alpha") lu.log(" Serving @ " + str(lu.getAddr()) + ":" + str(lu.getPort("alpha"))) httpd.serve_forever() except OSError: lu.error("Port in use - " + str(lu.getPort("alpha"))) except KeyboardInterrupt: sys.exit(0)
elif args[i] == "-y" : skipVerification=1 elif args[i] == "-h" : print(" " + sys.argv[0] + " <comp1> <comp2> <comp..> <options>") print(" Options:") for i in help: print("\t{:5}{:20}".format(i[0],i[1])) exit(0) else: compList.append(args[i]) i=i+1 # ========================== # Option Log # ========================== lu.log("Docker Mode Enabled : " + str(bool(dockerMode))) lu.log("Skip Verification messages : " + str(bool(skipVerification))) lu.log("Specified component list : " + str(compList)) # ========================== # Main Method # ========================== def main(): global termEmulator components=["alpha","lambda-M","lambda-m","omega","delta"] setup=[] error=[] for arg in compList: arg=re.sub("[^a-zA-Z0-9\-]", "", arg) # remove any none num or alpha char if arg in components: setup.append(arg)
def __init__(self): socketserver.TCPServer.allow_reuse_address = True tableRequestServer = socketserver.TCPServer((lu.getAddr(), 0), tableRequestHandler) # HTTP broadcastThread = threading.Thread(target=self._threadServe, args = (tableRequestServer,)).start() # serve HTTP in thread self.port = tableRequestServer.server_address[1] lu.log("Serving HTTP Get Table Requests @ " + str(lu.getAddr()) + ":" + str(self.port))
def do_DELETE(self): lu.log("Delete Request - " + self.path) self._setHeaders() self.wfile.write(b"<html><body><h1>delete!</h1></body></html>")