def __port_legal(self, ip, port): ret = nc_ip_port_available(ip, port) if ret: #logging.info('port: %s is used :%s' % (port, str(ret))) return False else: return True
def __get_needed_ports(self, host_ip, start_port, port_count): port_list = [] while True: start_port += 1 if start_port > 65535: raise CommonException('port are not enough, maybe start port are too small') if not nc_ip_port_available(host_ip, start_port): port_list.append(start_port) if len(port_list) >= port_count: break return port_list
def check(self): monitor_type, monitor_key, error_record = 'beehive', 'node', '' zk_opers = Scheduler_ZkOpers() host_ip_list = zk_opers.retrieve_data_node_list() beehive_port, monitor_port = 8888, 6666 alarm_level = options.alarm_nothing for host_ip in host_ip_list: beehive_ret = nc_ip_port_available(host_ip, beehive_port) if not beehive_ret: alarm_level = options.alarm_serious error_record += 'server:%s , beehive service is not running, please check!;' % host_ip monitor_ret = nc_ip_port_available(host_ip, monitor_port) if not monitor_ret: alarm_level = options.alarm_serious error_record += 'server:%s , container-monitor-agent service is not running, please check!;' % host_ip super(CheckBeehiveAlived, self).write_status(0, 0, 0, alarm_level, error_record, monitor_type, monitor_key)
def retrieve_port(self, host_ip, port_count): clusterUUID = self.getClusterUUID() path = "%s/%s/portPool/%s" % (self.rootPath, clusterUUID, host_ip) rest_port_list = self._return_children_to_list(path) assign_port_list = [] for port in rest_port_list: port_path = path + "/" + port self.DEFAULT_RETRY_POLICY(self.zk.delete, port_path) if not nc_ip_port_available(host_ip, port): assign_port_list.append(port) if len(assign_port_list) == port_count: break return assign_port_list