Beispiel #1
0
    def generate_container_names(self, component_type, count, cluster):

        names, container_numbers = [], []
        mid_name = _name.get(component_type)
        zk_opers = Container_ZkOpers()
        exists = zk_opers.check_containerCluster_exists(cluster)
        if not exists:
            for i in range(int(count)):
                container_name = 'd-%s-%s-n-%s' % (mid_name, cluster,
                                                   str(i + 1))
                names.append(container_name)
        else:
            containers = zk_opers.retrieve_container_list(cluster)
            for container in containers:
                container_value = zk_opers.retrieve_container_node_value(
                    cluster, container)
                container_name = container_value.get('containerName')
                container_prefix, container_number = re.findall(
                    '(.*-n-)(\d+)', container_name)[0]
                container_numbers.append(int(container_number))
            max_number = max(container_numbers)
            if max_number < 4:
                max_number = 4
            for i in range(int(count)):
                max_number += 1
                add_container_name = container_prefix + str(max_number)
                names.append(add_container_name)
        return names
    def __get_params(self):
        """
            two containers may be with a host_ip
        """

        params, container_info, container_nodes = {}, {}, []

        zkOper = Container_ZkOpers()
        if self.containers:
            for container in self.containers:
                container_node = self.container_opers.get_container_node_from_container_name(
                    self.cluster, container)
                container_nodes.append(container_node)
        else:
            container_nodes = zkOper.retrieve_container_list(self.cluster)
        self.container_nodes = container_nodes
        for container_node in self.container_nodes:
            container_name_list = []
            container_info = zkOper.retrieve_container_node_value(
                self.cluster, container_node)
            container_name = container_info.get('containerName')
            host_ip = container_info.get('hostIp')
            container_name_list.append(container_name)
            if host_ip in params:
                container_name_list.extend(params[host_ip])
            params[host_ip] = container_name_list
        return params
Beispiel #3
0
 def get_container_name_from_zk(self, cluster, container_node):
     zkOper = Container_ZkOpers()
     container_info = zkOper.retrieve_container_node_value(
         cluster, container_node)
     inspect = container_info.get('inspect')
     con = Container_Model(inspect=inspect)
     return con.name()
Beispiel #4
0
    def retrieve_container_node_value_from_containerName(self, container_name):
        cluster = get_containerClusterName_from_containerName(container_name)
        container_node = self.get_container_node_from_container_name(
            cluster, container_name)

        zkOper = Container_ZkOpers()
        node_value = zkOper.retrieve_container_node_value(
            cluster, container_node)
        return node_value
 def __exclude_servers(self, cluster):
     host_ip_list = []
     zk_opers = Container_ZkOpers()
     container_list = zk_opers.retrieve_container_list(cluster)
     for container in container_list:
         container_value = zk_opers.retrieve_container_node_value(
             cluster, container)
         host_ip = container_value.get('hostIp')
         host_ip_list.append(host_ip)
     return host_ip_list
Beispiel #6
0
    def get_container_node_from_container_name(self, cluster, container_name):
        con_node = ''
        zkOper = Container_ZkOpers()
        cluster_info = zkOper.retrieve_container_cluster_info(cluster)
        use_ip = cluster_info.get('isUseIp')
        if use_ip:
            container_node_list = zkOper.retrieve_container_list(cluster)
            for container_node in container_node_list:
                container_info = zkOper.retrieve_container_node_value(
                    cluster, container_node)
                inspect = container_info.get('inspect')
                con = Container_Model(inspect=inspect)
                con_name = con.name()
                if container_name == con_name:
                    con_node = container_node
                    break
        else:
            con_node = container_name

        return con_node
Beispiel #7
0
 def get_host_ip_from_zk(self, cluster, container_node):
     zkOper = Container_ZkOpers()
     container_info = zkOper.retrieve_container_node_value(
         cluster, container_node)
     return container_info.get('hostIp')