def create_host_by_host(ip_addr): port = PORT path = DATA_PATH name = ip_addr h = Host.create_host(name, path, ip_addr, port) h = h.to_json() if h else None return h
def init_db(): db.create_tables([Obj, Bucket, Host], safe=True) h = Host.update_path(name="localhost", path=DATA_PATH) if h: return h = Host.create_host(name="localhost", path=DATA_PATH, ip_addr="localhost") msg = "Init host success !" if h else "Error: init host failed !" print(msg)
def post(self): """ 添加主机 """ params = request.get_json() if not params: return APIResponse(code=BAD_REQUEST) name = params.get("name") path = params.get("path") port = params.get("port") ip_addr = params.get("ip_addr") username = params.get("username") password = params.get("password") host = Host.create_host(name, path, ip_addr, port, username, password) host = host.to_json() if host else None return APIResponse(code=0, data=host)