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_cluster_zk(self, cluster_name): cluster_zk_info = {} zkOper = Requests_ZkOpers() container_ip_list = zkOper.retrieve_container_list(cluster_name) for container_ip in container_ip_list: container_node = {} create_info = zkOper.retrieve_container_node_value( cluster_name, container_ip) status = zkOper.retrieve_container_status_value( cluster_name, container_ip) container_node.setdefault('container_info', create_info) container_node.setdefault('status', status) cluster_zk_info.setdefault(container_ip, container_node) return cluster_zk_info
def __cluster_created_info(self, cluster): zkOper = Requests_ZkOpers() message_list = [] container_node_list = zkOper.retrieve_container_list(cluster) result = {} for container_node in container_node_list: container_node_value = zkOper.retrieve_container_node_value( cluster, container_node) con = Container_Model() create_info = con.create_info(container_node_value) message_list.append(create_info) result.setdefault('containers', message_list) return result
def __created_info(self, cluster, container_names=[]): zkOper = Requests_ZkOpers() message_list, container_nodes = [], [] if container_names: for container_name in container_names: container_node = self.container_opers.get_container_node_from_container_name( cluster, container_name) if not container_node: raise UserVisiableException('container :%s not existed' % container_name) container_nodes.append(container_node) else: container_nodes = zkOper.retrieve_container_list(cluster) result = {} for container_node in container_nodes: container_node_value = zkOper.retrieve_container_node_value( cluster, container_node) con = Container_Model() create_info = con.create_info(container_node_value) message_list.append(create_info) result.setdefault('containers', message_list) return result