import os, io, sys, platform, shutil, time, json, datetime import re,docker,requests from api.utils import shell_execute from api.utils import network 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 get_process_perc(app_name, real_name): process_now = "pulling" image_name = real_name if real_name == "codeserver": image_name = "code-server" elif real_name == "codeserver2": image_name = "code-server2" output = shell_execute.execute_command_output_all("sudo docker image list |grep " + image_name) code = output["code"] if int(code) == 0 and output["result"] != "": process_now = "starting" output = shell_execute.execute_command_output_all("docker inspect " + app_name + "|grep error") code = output["code"] if int(code) == 0 and output["result"] == "": process_now = "Initializing" return process_now 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