def cluster_resoure(self, cluster, resource_type): zkOper = Requests_ZkOpers() exists = zkOper.check_containerCluster_exists(cluster) if not exists: error_message = 'container cluster %s not exist, please check your cluster name' % cluster raise HTTPAPIError(status_code=417, error_detail=error_message, notification="direct", log_message=error_message, response=error_message) container_node_list = zkOper.retrieve_container_list(cluster) result = [] for container_node in container_node_list: resource = {} resource_value = zkOper.retrieve_container_resource(cluster, container_node, resource_type) host_ip = self.container_opers.get_host_ip_from_zk(cluster, container_node) container_name = self.container_opers.get_container_name_from_zk(cluster, container_node) resource.setdefault('value', resource_value) resource.setdefault('hostIp', host_ip) resource.setdefault('containerName', container_name) result.append(resource) return result
def get_container_resource(self, container_name, resource_type): zk_opers = Requests_ZkOpers() result = {} cluster_name = get_containerClusterName_from_containerName( container_name) node_name = self.container_opers.get_container_node_from_container_name( cluster_name, container_name) resource_value = zk_opers.retrieve_container_resource( cluster_name, node_name, resource_type) result.setdefault('value', resource_value) result.setdefault('containerName', container_name) return result