1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- from fastapi import FastAPI
- from pydantic import BaseModel
- from utils import dmQuery
- from utils.shellUtil import execute_command_on_linux
- app = FastAPI() # 创建API实例
- @app.get("/")
- async def root():
- return {"message": "Hello World"}
- # 将数据模型定义为继承BaseModel的类
- class Item(BaseModel):
- sql: str
- @app.put("/exsql")
- async def create_item( item: Item, q: str = None):
- result = {**item.dict()}
- results = dmQuery.execute_query(item.sql)
- return results
- @app.put("/exshell")
- async def create_item( item: Item, q: str = None):
- # 配置 Linux 服务器信息
- host = '119.29.146.254'
- port = 22
- username = 'root'
- password = 'zrd1236987!'
- # 要执行的命令
- result = execute_command_on_linux(host, port, username, password, item.sql)
- return result
|