from concurrent.futures import ThreadPoolExecutor
from .volc_cloud import VolcCloudECS

class VolcECS:
    def __init__(self):
        self.volcano_cloud = None
        self.total_cpu = 0
        self.total_memory = 0
        self.total_disk = 0
        self.cloud_resources = []

    def init_cloud_provider(self):
        try:
            self.volcano_cloud = VolcCloudECS()
        except EnvironmentError as e:
            print(f"火山云初始化失败: {e}")

    def get_volcano_resources(self):
        """获取火山云资源"""
        if not self.volcano_cloud:
            return None
        try:
            resources = self.volcano_cloud.get_total_resources()
            return resources
        except Exception as e:
            print(f"获取火山云资源失败: {e}")
            return None

    def collect_cloud_resources(self):
        """收集云资源"""
        if self.volcano_cloud:
            try:
                resources = self.get_volcano_resources()
                if resources:
                    self.cloud_resources.append(resources)
            except Exception as e:
                print(f"获取火山云资源失败: {e}")

    def calculate_total_sum(self):
        for resource in self.cloud_resources:
            self.total_cpu += resource["cpu"]
            self.total_memory += resource["memory"]
            self.total_disk += resource["disk"]

    def print_result(self):
        print(f"Volc ECS：CPU={self.total_cpu}核，memory={self.total_memory}GB，disk={self.total_disk}GB")
