Ejemplo n.º 1
0
    def get_dc_cluster_info(self):
        """获取vcenter平台中集群的详细信息"""
        cluster_info_list = []

        for datacenter in self._dc_cluster.keys():
            for cluster in self._dc_cluster[datacenter]:
                for clusterref in vmwareop.get_cluster_ref(
                        self._session, cluster):
                    (totalCapacity,
                     freeCapacity) = vmwareop.get_object_datastore(
                         self._session, clusterref, 'ClusterComputeResource')
                    used = com_utils.convert_kb_to_g(totalCapacity -
                                                     freeCapacity)
                    free = com_utils.convert_kb_to_g(freeCapacity)
                    total = com_utils.convert_kb_to_g(totalCapacity)
                    cpu_num, memory_size = self.get_cluster_cpu_memory(
                        clusterref)
                    memory = com_utils.convert_kb_to_g(memory_size)
                    #                     print "memory_size:", memory_size, cpu_num
                    cluster_info_list.append({"name": cluster, "datacenter": datacenter,
                                              "virtualplatformtype": self.virt_type, \
                                              "domain": self._domain_name, \
                                              "cpu": cpu_num, "memory": memory, \
                                              "free": free, "used": used, "total": total})
#         print "cluster_info_list:", cluster_info_list
        return cluster_info_list
Ejemplo n.º 2
0
    def get_dc_datastore(self, dc_id):
        '''
        获取数据中心下的存储容量
        :param dc_id :数据中心的id
        :return 元组(储存总量,已使用量)
        '''
        totalCapacity = 0
        freeCapacity = 0
        used = 0
        storages_info = self._request.getRequestInfo(
            common.CSERVER_DC_STORAGE_URL % dc_id)
        if storages_info and storages_info.has_key("storage_domain"):
            storages = storages_info["storage_domain"]
            if storages and len(storages) > 0:
                for storage in storages:
                    totalCapacity += storage["available"] + storage["used"]
                    freeCapacity += storage["available"]
                    used += storage["used"]

        totalCapacity = com_utils.convert_kb_to_g(totalCapacity)
        freeCapacity = com_utils.convert_kb_to_g(freeCapacity)
        used = com_utils.convert_kb_to_g(used)

        #         print (totalCapacity,freeCapacity, used)
        return (used, freeCapacity, totalCapacity)
Ejemplo n.º 3
0
    def get_dc_cluster_host_info(self):
        """获取vcenter平台中主机的详细信息"""
        host_info_list = []

        for datacenter in self._dc_cluster.keys():
            for cluster in self._dc_cluster[datacenter]:
                for clusterref in vmwareop.get_cluster_ref(
                        self._session, cluster):
                    for host in vmwareop.get_cluster_host(
                            self._session, clusterref):
                        hostip = ""
                        if host[0]:
                            hostip = host[0][0]
                        hostname = host[1]
                        hostref = host[2]
                        host_status = vmwareop.get_host_status(
                            self._session, hostref)
                        host_cpu_num, host_cpu_hz = vmwareop.get_host_cpu_info(
                            self._session, hostref)
                        host_memory = com_utils.convert_kb_to_g(
                            vmwareop.get_host_memSize(self._session, hostref))
                        host_info_list.append({"name": hostname, "datacenter": datacenter, \
                                               "domain": self._domain_name, \
                                               "address": hostip, "cluster": cluster, \
                                               "status": host_status, "cpu": host_cpu_num,\
                                               "memory": host_memory})

        return host_info_list
Ejemplo n.º 4
0
 def get_dc_datastore(self):
     """获取vcenter平台中数据中心的存储信息"""
     dc_ds_info = {}
     for dc in vmwareop.list_datacenter(self._session):
         datacenter_name = str(dc[0])
         dc_ref = dc[1]
         totalCapacity = 0
         freeCapacity = 0
         used = 0
         if datacenter_name in self._dc_cluster.keys():
             (totalCapacity, freeCapacity) = vmwareop.get_object_datastore(
                 self._session, dc_ref, 'Datacenter')
             used = totalCapacity - freeCapacity
             dc_ds_info[datacenter_name] = [com_utils.convert_kb_to_g(used), \
                                            com_utils.convert_kb_to_g(freeCapacity), \
                                            com_utils.convert_kb_to_g(totalCapacity)]
     return dc_ds_info
Ejemplo n.º 5
0
 def get_sll_dc_cpu_memeory(self):
     """获取cserver平台中接管的所有数据中心的cpu和内存信息"""
     dc_cpu_num = 0
     dc_memory_size = 0
     for datacenter in self._session.get_datacenter_list():
         if datacenter["name"] in self._dc_cluster.keys():
             for cluster in self._session.get_dc_cluster(datacenter['id']):
                 if cluster["name"] in self._dc_cluster[datacenter["name"]]:
                     cpu_memory_info = self.get_cluster_cpu_memory(
                         cluster['id'])
                     dc_cpu_num += cpu_memory_info[0]
                     dc_memory_size += cpu_memory_info[1]
     return dc_cpu_num, com_utils.convert_kb_to_g(dc_memory_size)
Ejemplo n.º 6
0
    def get_dc_cluster_info(self):
        """获取cserver平台中集群的详细信息"""
        cluster_info_list = []
        if not self._dc_cluster:
            return []

        for datacenter in self._session.get_datacenter_list():
            for datacenter["name"] in self._dc_cluster.keys():
                for cluster in self._session.get_dc_cluster(datacenter['id']):
                    if cluster["name"] in self._dc_cluster[datacenter["name"]]:
                        cpu_num, memory_size = self.get_cluster_cpu_memory(
                            cluster["id"])
                        memory = com_utils.convert_kb_to_g(memory_size)
                        cluster_info_list.append({"name": cluster["name"], "datacenter": datacenter["name"],
                                                  "virtualplatformtype": self.virt_type, \
                                                  "domain": self._domain_name, "id": cluster["id"], \
                                                  "cpu": cpu_num, "memory": memory, \
                                                  "free": "0", "used": "0", "total": "0"})
        return cluster_info_list
Ejemplo n.º 7
0
    def get_dc_info(self):
        """获取vcenter平台中数据中心的详细信息"""
        dc_info_list = []

        dc_ds_info = self.get_dc_datastore()
        for dc in self._dc_cluster.keys():
            used = dc_ds_info[dc][0] if dc_ds_info else 0
            freeSpace = dc_ds_info[dc][1] if dc_ds_info else 0
            capacity = dc_ds_info[dc][2] if dc_ds_info else 0
            cpu_num, memory_size = self.get_dc_cpu_memeory()
            memory = com_utils.convert_kb_to_g(memory_size)
            dc_info_list.append({"name": dc, "mcenter": self._name, \
                                 "cpu": cpu_num, "memory": memory, \
                                 "free": freeSpace, "used": used, \
                                 "capacity": capacity, \
                                 "domain": self._domain_name, \
                                              })
#         print "dc_info_list:", dc_info_list

        return dc_info_list
Ejemplo n.º 8
0
    def get_dc_cluster_host_info(self, is_monitor=False):
        """获取cserver平台中主机的详细信息"""
        host_info_list = []
        if not self._dc_cluster:
            return []

        for datacenter in self._session.get_datacenter_list():
            if datacenter["name"] in self._dc_cluster.keys():
                for cluster in self._session.get_dc_cluster(datacenter['id']):
                    if cluster["name"] in self._dc_cluster[datacenter["name"]]:
                        for host in self._session.get_cluster_host(
                                cluster["id"]):
                            host_status, host_cpu_num, memory_size = self._session.get_host_status_cpu_memory_info(
                                host["id"])
                            host_memory = com_utils.convert_kb_to_g(
                                memory_size)
                            network_receive_rate = network_transmit_rate = 0
                            network_usage = host_cpu_usage = host_memory_usage = network_flow = 0
                            timestamp = ""
                            address = self._session.get_host_address(
                                host["id"])
                            if is_monitor:
                                network_receive_rate, network_transmit_rate = self._session.get_host_network_rate(
                                    host["id"])
                                network_usage = self._session.get_host_network_usage(
                                    host["id"])
                                host_cpu_usage, host_memory_usage = self._session.get_host_cpu_memory_usage(
                                    host["id"])
                                network_flow = network_receive_rate + network_transmit_rate
                                timestamp = datetime.today()
                            host_info_list.append({"name": host["name"], "datacenter": datacenter["name"], "timestamp": timestamp, \
                                                   "domain": self._domain_name, "cluster": cluster["name"], \
                                                   'network_receive_rate': network_receive_rate, \
                                                   "network_transmit_rate": network_transmit_rate, \
                                                   "network_flow": network_flow, \
                                                   "status": host_status, "cpu": host_cpu_num, "network_usage": network_usage, "address": address, \
                                                   "memory": host_memory, "memory_usage": host_memory_usage, "cpu_usage": host_cpu_usage})
#         print "host_info_list:", host_info_list

        return host_info_list