Example #1
0
 def get_ip_num(self):
     """
         monitor item: get ip num from ip Pool
     """
     zkOper = Common_ZkOpers()
     ip_list = zkOper.get_ips_from_ipPool()
     return len(ip_list)
Example #2
0
    def validateResource(self, component_container_cluster_config):
        zkOper = Common_ZkOpers()
        ip_list = zkOper.get_ips_from_ipPool()
        nodeCount = component_container_cluster_config.nodeCount

        if len(ip_list) < nodeCount:
            raise CommonException('ips are not enough!')
Example #3
0
    def _get_needed_ips(self, ip_segment, ip_count):
        choosed_ip = []

        zkOper = Common_ZkOpers()
        ip_list = zkOper.get_ips_from_ipPool()

        all_ips = self._get_all_ips(ip_segment)
        ips = list(set(all_ips) - set(ip_list))
        num = 0
        if len(ips) < ip_count:
            logging.info('ips usable are not enough, just add %s ips' %
                         len(ips))
            ip_count = len(ips)

        for ip in ips:
            if self.__ip_legal(ip):
                choosed_ip.append(ip)
                num += 1
            if num == ip_count:
                break
        return choosed_ip
Example #4
0
    def get_illegal_ips(self, thread_num):
        """check ip pools
           
           thread_num: how many thread to do check if ip is legal
           put all ips in ip pools into store_all_ips_queue,
           do check ip is legal in  threads, if illegal, put illegal ip into store_illegal_ips_queue,
           if all threads end, get illegal ips and return them
        """

        illegal_ips, thread_obj_list = [], []
        zkOper = Common_ZkOpers()
        ip_list = zkOper.get_ips_from_ipPool()
        logging.info('put all ips in ip pools into store_all_ips_queue')

        self.store_all_ips_queue._init(0)
        self.store_all_ips_queue.queue.extend(ip_list)

        logging.info('queue size :%s' % str(self.store_all_ips_queue.qsize()))
        for i in range(thread_num):
            thread_obj = doInThread(self.__ips_legal)
            thread_obj_list.append(thread_obj)

        while thread_obj_list:
            succ = []
            for thread_obj in thread_obj_list:
                if not thread_obj.isAlive():
                    succ.append(thread_obj)
            for item in succ:
                thread_obj_list.remove(item)
            time.sleep(0.5)

        logging.info('get illegal_ip')
        while not self.store_illegal_ips_queue.empty():
            illegal_ip = self.store_illegal_ips_queue.get(block=False)
            illegal_ips.append(illegal_ip)
        logging.info('illegal_ips :%s' % str(illegal_ips))
        return illegal_ips