import os, io, sys, platform, shutil, time, json, datetime import re,docker,requests from api.utils import shell_execute import psutil as p from dotenv import load_dotenv, find_dotenv import dotenv from pathlib import Path from api.utils.common_log import myLogger def pull_images(app_name): # 备用方法 # 为了防止安装前,用户服务器已经有了镜像。导致安装时镜像不重新拉取,镜像是老的(根据docker-compose.yml 和 .env 获取) myLogger.info_logger("Pull images complete ...") def delete_images(app_id): # 备用方法 # 卸载APP时同时删除dockercompose里面对应的镜像(根据docker-compose.yml 和 .env 获取) myLogger.info_logger("Delete images complete ...") def get_process_perc(app_name, real_name): process_now = "step1" if if_app_exits(app_name): process_now = "step2" process_now = "step3" return process_now def if_app_exits(app_name): cmd = "docker compose ls -a | grep \'"+app_name+"\\b\'" output = shell_execute.execute_command_output_all(cmd) if int(output["code"]) == -1: return False else: return True def check_vm_resource(app_name): myLogger.info_logger("Checking virtual memory resource ...") cpu_count = p.cpu_count() mem = p.virtual_memory() mem_total = float(mem.total) / 1024 / 1024 / 1024 requirements_var = read_var(app_name, 'requirements') need_cpu_count = int(requirements_var['cpu']) need_mem = int(requirements_var['memory']) if cpu_count=8 and mem_free<=4: return False need_disk = int(requirements_var['disk']) disk = p.disk_usage('/') disk_total = float(disk.total) / 1024 / 1024 / 1024 disk_free = float(disk.free) / 1024 / 1024 / 1024 if disk_total