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)
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 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 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")
<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)