示例#1
0
    def create_result(self, containerClusterName, container_names=[]):
        create_successful = {'code': "000000"}
        creating = {'code': "000001"}
        create_failed = {'code': "000002", 'status': Status.create_failed}

        zkOper = Requests_ZkOpers()
        exists = zkOper.check_containerCluster_exists(containerClusterName)
        if not exists:
            raise UserVisiableException('containerCluster %s not existed' %
                                        containerClusterName)

        result = {}

        container_cluster_info = zkOper.retrieve_container_cluster_info(
            containerClusterName)
        start_flag = container_cluster_info.get('start_flag')

        if start_flag == Status.failed:
            result.update(create_failed)
            result.setdefault('error_msg', 'create containers failed!')

        elif start_flag == Status.succeed:
            create_info = self.__created_info(containerClusterName,
                                              container_names)
            result.update(create_successful)
            result.update(create_info)
        else:
            result.update(creating)
        return result
示例#2
0
    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
示例#3
0
    def check(self, containerClusterName):
        zkOper = Requests_ZkOpers()
        exists = zkOper.check_containerCluster_exists(containerClusterName)
        if not exists:
            raise UserVisiableException('containerCluster %s not existed' %
                                        containerClusterName)

        cluster_status = self.component_container_cluster_validator.container_cluster_status_validator(
            containerClusterName)
        return cluster_status