websoft9/appmanage/api/service/manage.py

30 lines
888 B
Python
Raw Normal View History

2023-02-21 14:21:53 +08:00
import os, io, sys, platform, shutil, time, subprocess, json, datetime
from api.utils import shell_execute
2023-02-22 17:45:54 +08:00
# 获取所有app的信息
2023-02-22 17:21:46 +08:00
def get_my_app():
2023-02-21 14:21:53 +08:00
2023-02-22 21:27:25 +08:00
my_cmd = "sudo docker compose ls"
2023-02-22 17:21:46 +08:00
output = shell_execute.execute_command_output_all(my_cmd)
if int(output["code"]) == 0:
output_list = output["result"].split()
print(output_list)
2023-02-22 21:27:25 +08:00
ret = {}
2023-02-22 17:21:46 +08:00
list = []
num = int(len(output_list)/3)
for i in range(1,num):
app = {}
app['name'] = output_list[3*i+1]
app['status_code'] = output_list[3*i+2].split("(")[0]
app['status'] = output_list[3*i+3]
list.append(app)
2023-02-22 21:27:25 +08:00
ret["code"] = 0
ret["message"] = "app查询成功"
ret["data"] = list
else:
ret["code"] = -1
ret["message"] = "app查询失败"
ret["data"] = None
return ret