def __init__(self, token, hostname, ip, mode): threading.Thread.__init__(self) self.o = SysRp() self.token = token self.hostname = hostname self.ip = ip self.mode = mode
class ThreadOverHead(threading.Thread): def __init__(self, token): threading.Thread.__init__(self) self.o = SysRp() self.token = token def run(self): self.o.mountImgCompress(self.token) event.set()
class ThreadRescuteMode(threading.Thread): def __init__(self, token, hostname, ip, mode): threading.Thread.__init__(self) self.o = SysRp() self.token = token self.hostname = hostname self.ip = ip self.mode = mode def run(self): self.o.changePartition(self.ip, self.mode) print(self.o.reboot(self.token, self.hostname))
class Run(object): def __init__(self, token): self.rP = RpCloud() self.arp = Arp() self.sys = SysRp() # Inicia la app self.start(token) def start(self, token): checked = self.rP.checkLogin(token) if (checked): # Consultamos el JSON actual (peticion ARP) generatedJson = self.sys.generateJson(token) # Ejecuta un hilo para montar y comprimir la imagen en el servidor threadOverHead1 = ThreadOverHead( token, "/mnt/img/uploads/minimalRaspyCloud.img") threadOverHead1.start() for pi in generatedJson.get("raspberryPi"): # Crea un hilo por cada raspberryPi hThread1 = Thread(token, pi.get("hostname"), pi.get("ip")) hThread1.start() return "Done" else: return "Invalid Token"
def application(request): # get the request path # print(request.path) # get the request host # print(request.host) # get the request method print(request.args.get('PATH_INFO')) arpObject = Arp() rpCloudObject = RpCloud() sysRpObject = SysRp() # Dispatcher is dictionary {<method_name>: callable} dispatcher['scanARP'] = arpObject.update dispatcher['getArpTable'] = arpObject.getTable dispatcher['login'] = rpCloudObject.login dispatcher['checkPassword'] = rpCloudObject.checkPassword dispatcher['checkLogin'] = rpCloudObject.checkLogin dispatcher['logout'] = rpCloudObject.logout dispatcher['getHostname'] = sysRpObject.getHostname dispatcher['reboot'] = sysRpObject.reboot dispatcher['setHostname'] = sysRpObject.setHostname dispatcher['generateJson'] = sysRpObject.generateJson dispatcher['storageJson'] = sysRpObject.storageJson response = JSONRPCResponseManager.handle(request.data, dispatcher) return Response(response.json, mimetype='application/json')
class Rescute(object): def __init__(self, token, mode): self.rP = RpCloud() self.arp = Arp() self.sys = SysRp() # Inicia la app self.start(token, mode) def start(self, token, mode): # Consultamos el JSON actual (peticion ARP) generatedJson = self.sys.generateJson(token) for pi in generatedJson.get("raspberryPi"): # Crea un hilo por cada raspberryPi hThreadRescute = ThreadRescuteMode(token, pi.get("hostname"), pi.get("ip"), mode) hThreadRescute.start() return "Done"
def __init__(self, token): threading.Thread.__init__(self) self.o = SysRp() self.token = token
class Thread(threading.Thread): def __init__(self, token, hostname, ip): threading.Thread.__init__(self) self.o = SysRp() self.token = token self.hostname = hostname self.ip = ip def run(self): self.o.createPartition(self.ip) self.o.reboot(self.token, self.hostname) self.o.formatFileSystemAndMount(self.ip) event.wait() self.o.sendAndDecompress(self.ip) self.o.changePartition(self.ip, False) print(self.o.reboot(self.token, self.hostname))
def __init__(self, token): self.rP = RpCloud() self.arp = Arp() self.sys = SysRp() # Inicia la app self.start(token)
def apiGenerateJson(token): return SysRp().generateJson(token)