websoft9/appmanage/api/v1/routers/apps.py

56 lines
2.1 KiB
Python
Raw Normal View History

2023-02-21 14:21:53 +08:00
from typing import Optional, List
from fastapi import APIRouter, status, Depends
from pydantic import BaseModel
from starlette.responses import JSONResponse
2023-02-22 17:19:27 +08:00
import os, io, sys, platform, shutil, time, subprocess, json, datetime
2023-02-21 14:21:53 +08:00
from api.model.app import App
from api.service import manage
2023-02-22 17:19:27 +08:00
from api.utils import shell_execute
2023-03-15 17:55:05 +08:00
from api.utils.common_log import myLogger
2023-02-21 14:21:53 +08:00
router = APIRouter()
2023-03-15 14:07:04 +08:00
@router.api_route("", methods=["GET", "POST"])
2023-02-22 17:19:27 +08:00
def list_my_apps():
2023-03-15 17:55:05 +08:00
myLogger.info_logger("Receive request: /api/v1/apps")
2023-02-22 17:19:27 +08:00
list = manage.get_my_app()
return JSONResponse(content=list)
2023-02-21 14:21:53 +08:00
2023-03-15 14:23:51 +08:00
@router.api_route("/install", methods=["GET", "POST"])
2023-03-15 15:23:10 +08:00
def install_app(app_name: Optional[str] = None, customer_app_name: Optional[str] = None, app_version: Optional[str] = None):
2023-03-15 17:55:05 +08:00
myLogger.info_logger("Receive request: /api/v1/apps/install")
2023-03-15 15:23:10 +08:00
ret = manage.install_app(app_name, customer_app_name, app_version)
2023-02-23 16:19:55 +08:00
return JSONResponse(content=ret)
2023-02-22 17:43:09 +08:00
2023-03-15 14:23:51 +08:00
@router.api_route("/process", methods=["GET", "POST"])
2023-03-15 11:43:04 +08:00
def install_app_process(app_id: Optional[str] = None):
2023-03-15 17:55:05 +08:00
myLogger.info_logger("Receive request: /api/v1/apps/process")
2023-03-15 11:43:04 +08:00
ret = manage.install_app_process(app_id)
2023-03-09 10:29:11 +08:00
return JSONResponse(content=ret)
2023-03-15 14:23:51 +08:00
@router.api_route("/start", methods=["GET", "POST"])
2023-03-15 11:43:04 +08:00
def start_app(app_id: Optional[str] = None):
2023-03-15 17:55:05 +08:00
myLogger.info_logger("Receive request: /api/v1/apps/start")
2023-03-15 11:43:04 +08:00
ret = manage.start_app(app_id)
2023-02-28 17:44:04 +08:00
return JSONResponse(content=ret)
2023-02-25 11:37:39 +08:00
2023-03-15 14:23:51 +08:00
@router.api_route("/stop", methods=["GET", "POST"])
2023-03-15 11:43:04 +08:00
def stop_app(app_id: Optional[str] = None):
2023-03-15 17:55:05 +08:00
myLogger.info_logger("Receive request: /api/v1/apps/stop")
2023-03-15 11:43:04 +08:00
ret = manage.stop_app(app_id)
2023-02-28 17:44:04 +08:00
return JSONResponse(content=ret)
2023-02-25 11:37:39 +08:00
2023-03-15 14:23:51 +08:00
@router.api_route("/restart", methods=["GET", "POST"])
2023-03-15 11:43:04 +08:00
def restart_app(app_id: Optional[str] = None):
2023-03-15 17:55:05 +08:00
myLogger.info_logger("Receive request: /api/v1/apps/restart")
2023-03-16 10:07:17 +08:00
ret = manage.restart_app(app_id)
2023-02-28 17:44:04 +08:00
return JSONResponse(content=ret)
2023-02-25 11:37:39 +08:00
2023-03-15 14:23:51 +08:00
@router.api_route("/uninstall", methods=["GET", "POST"])
2023-03-15 15:22:56 +08:00
def uninstall_app(app_id: Optional[str] = None):
2023-03-15 17:55:05 +08:00
myLogger.info_logger("Receive request: /api/v1/apps/uninstall")
2023-03-15 15:22:56 +08:00
ret = manage.uninstall_app(app_id)
2023-02-28 17:44:04 +08:00
return JSONResponse(content=ret)