def restart_instance(uid, priv, inst_id): # don't forget to check if this user is allowed to get inst info is_user = db.session.query(ServerInstance).filter( ServerInstance.owner_id == uid).filter( ServerInstance.inst_id == inst_id) if is_user == None: return rtn.error(403) props = {"inst_id": inst_id} proxy.send("process.restart_instance", props, WS_TAG.MPW, reply=False) return rtn.success(200)
def send_command(uid, priv, inst_id): # don't forget to check if this user is allowed to get inst info is_user = db.session.query(ServerInstance).filter( ServerInstance.owner_id == uid).filter( ServerInstance.inst_id == inst_id) if is_user == None: return rtn.error(403) G = request.args props = {"inst_id": inst_id, "command": G.get("command")} proxy.send("process.send_command", props, WS_TAG.MPW, reply=False) return rtn.success(200)
def start_download_java(uid, priv): G = request.args _index = G.get("index") source = sourceJAVA() _list = source.get_download_list() if _index.isdigit() == False: return rtn.error(402) _index = int(_index) if _index >= len(_list) or _index < 0: return rtn.error(402) else: _v = { "download_link": source.get_download_link(None, None, index=_index), "binary_dir": source.get_binary_directory(None, None, index=_index), "major_version": _list[_index].get("major"), "minor_version": _list[_index].get("minor"), "uid": uid } _tasks_obj = proxy.send("task.start_download", _v, WS_TAG.TSR, reply=False) return rtn.success(200)
def _set_ftp_account_name(self, value): if value == "" or value == None: return (False, 405) else: port_obj = db.session.query(FTPAccount).filter( FTPAccount.username == value) if port_obj.first() != None: # duplicated! return (False, 406) else: q = db.session.query(FTPAccount).filter( FTPAccount.inst_id == self.inst_id) q.update({"username": value}) db.session.commit() # announce FTP manager to update user proxy.send("ftp.update_users", {}, WS_TAG.FTM, reply=False) return (True, 200)
def _set_ftp_password(self, value): default = value.get("default") password = value.get("password") if password == None: password = "" if not default: _ftp_hash = hashlib.md5(password.encode("utf-8") + salt).hexdigest() else: _ftp_hash = None q = db.session.query(FTPAccount).filter( FTPAccount.inst_id == self.inst_id) q.update({"default_password": default, "hash": _ftp_hash}) db.session.commit() proxy.send("ftp.update_users", {}, WS_TAG.FTM, reply=False) return (True, 200)
def get_java_download_list(uid, priv): ''' init a list of all java versions. dw_list model: { "major" : ***, "minor" : ***, "link" : ***, "dw" : { "progress", "status, "current_hash", } } :param flag: :param values: :return: ''' source = sourceJAVA() _list = source.get_download_list() dw_list = [] for item in _list: _dw = {"progress": 0.0, "status": _utils.WAIT, "current_hash": ""} # fetch active download tasks _tasks_obj = proxy.send("task.download_pool_status", {}, WS_TAG.TSR) _tasks = _tasks_obj["data"] for task in _tasks: if _tasks[task]["link"] == item.get("link"): _dw["progress"] = _tasks[task]["progress"] _dw["status"] = _tasks[task]["status"] _dw["current_hash"] = task break # and fetch from database if there are some versions already installed. res = db.session.query(JavaBinary).filter( JavaBinary.major_version == str(item.get("major")), JavaBinary.minor_version == str(item.get("minor"))).first() # that means, this java version has record on the database if res != None: _dw["status"] = _utils.FINISH _model = { "major": item.get("major"), "minor": item.get("minor"), "link": item.get("link"), "dw": _dw } dw_list.append(_model) return rtn.success(dw_list)
def get_instance_status(uid, priv, inst_id): # don't forget to check if this user is allowed to get inst info is_user = db.session.query(ServerInstance).filter( ServerInstance.owner_id == uid).filter( ServerInstance.inst_id == inst_id) if is_user == None: return rtn.error(403) props = {"inst_id": inst_id} info = proxy.send("process.get_instance_status", props, WS_TAG.MPW) if info == None: return rtn.error(500) else: return rtn.success(info["data"])
def update_user(self): proxy.send("ftp.update_users", {}, WS_TAG.FTM, reply=False)