def p_heart_beat_timer(): global g_clc_ip global g_cc_ip if g_clc_ip!=None and g_cc_ip!=None: OpenLdap.p_all_heart_beat(g_clc_ip,g_cc_ip,'cluster') heart = threading.Timer(HEART_BEAT_INTV , p_heart_beat_timer) heart.start()
def luhya_clc_start_vm(self, clientInfo): """ harrison 远程模式(clientData.is_local==False): 直接调用ClcThriftServer API luhya_clc_start_vm(clientData)启动虚拟机 本地模式(clientData.is_local==True): 调用本地NcThriftServer API luhya_res_start_vm (clientData)启动虚拟机 """ ret = -1 if clientInfo.instance_state.is_local: local_nc_ip = utility.get_local_publicip() if local_nc_ip != None: ret = OpenLdap.p_nc_start_vm(local_nc_ip, clientInfo) else: logger.debug("get local ip is error!") else: ldap_ip = utility.get_real_ldap() if ldap_ip != None: clc_ip = OpenLdap.get_clc_ip(ldap_ip) if clc_ip != None: ret = OpenLdap.clc_start_vm(clc_ip, clientInfo) else: logger.debug("get real clc ip is error!") else: logger.debug("get real ldap ip is error!") return ret
def p_dispatch_nodes(): nodeIp = None ldap_ip = utility.get_ldap_server() clusterInfo = OpenLdap.p_get_clusterInfo_by_ccIp(ldap_ip,g_cc_ip) if clusterInfo!=None: nodes = OpenLdap.p_get_nodeInfo_by_clusterName(ldap_ip,clusterInfo.clusterName) if nodes!=None and len(nodes)>0: nodeIp = nodes[0].hostIp return nodeIp
def p_nc_heart_beat_isAlive(): logger.debug('p_nc_heart_beat_isAlive()') global g_nc_heart_beat heartT = time.time() for ip in g_nc_heart_beat: if (heartT - g_nc_heart_beat[ip]) < 4: logger.debug('NC %s is alive' % ip) else: logger.debug('NC %s is dead!!!' % ip) if g_clc_ip!=None: OpenLdap.luhya_nc_dead(g_clc_ip,ip,thd_SERVICE_TYPE.CLOUD_NC) heart = threading.Timer(4.0,p_nc_heart_beat_isAlive) heart.start()
def run(self): logger.info('p_transmit_server_source_thread...') while True: if g_wal_ip!=None and g_clc_ip!=None: hdSource = utility.utility_get_current_resource() g_source_switch.acquire() hdSource.net_receiverate = g_server_resource['recvRate'] hdSource.net_sendrate = g_server_resource['sendRate'] hdSource.cpu_utilization = g_server_resource['cpuUtilization'] g_source_switch.release() hdSource.state = 'HW_STATUS_OK' if hdSource.cpu_utilization > VM_CPU_UTILIZATION: hdSource.state = 'HW_STATUS_WARN' OpenLdap.p_transmit_hard_source(g_clc_ip,g_wal_ip,hdSource) time.sleep(SERVER_SOURCE_INTV)
def run(self): while True: time.sleep(INSTANCE_REPORT_INTV) logger.debug('p_transmit_transcationlist_thread:%s' %str(g_cc_transaction)) for nodeIp in g_cc_transaction.keys() : g_transaction_switch.acquire() transactions = g_cc_transaction[nodeIp][:] g_transaction_switch.release() logger.debug('p_transmit_transcationlist_thread transaction : %s' %str(transactions)) if g_clc_ip != None: transmitData = thd_transmit_data() transmitData.node_ip = nodeIp transmitData.transactions = transactions logger.debug('p_transmit_transcationlist_thread transmitData:%s: ' %str(transmitData)) OpenLdap.p_set_transmit_transactionlist(g_clc_ip,transmitData)
def run(self): logger.debug('p_get_nodeInfo_byClusterName_thread start ....') global g_nc_heart_beat while True: ldap_ip = utility.get_ldap_server() ret = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_CC,utility.get_local_publicip()) if ret: clusterInfo = OpenLdap.p_get_clusterInfo_by_ccIp(ldap_ip,g_cc_ip) if clusterInfo != None: nodeList = OpenLdap.p_get_nodeInfo_by_clusterName(ldap_ip,clusterInfo.clusterName) if nodeList != None: for nodeInfo in nodeList: g_nc_heart_beat[nodeInfo.hostIp] = time.time() break time.sleep(HEART_BEAT_INTV) logger.debug('waiting in p_get_nodeInfo_byClusterName_thread()!!!')
def run(self): while True: hostIp = utility.get_local_publicip() ldap_ip = utility.get_ldap_server() ret = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_WALRUS,hostIp) if ret: logger.info('g_WalrusThriftServer_main_interface running ...') handler = walrusApiHandler() processor = walrusApi.Processor(handler) transport = TSocket.TServerSocket(hostIp,thd_port.THRIFT_WALRUS_PORT) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() #server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) # You could do one of these for a multithreaded server #server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory) logger.info('Starting the server...') server.serve() logger.error('thrift server done') break else: time.sleep(2)
def run(self): while True: hostIp = utility.get_local_publicip() logger.info( 'g_ClusterThriftServer_main_interface cc register :%s ' %hostIp) ldap_ip = utility.get_ldap_server() # avoid the ip address cant be read if ldap_ip!=None: ret = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_CC,hostIp) if ret: logger.info('g_ClusterThriftServer_main_interface running ...') handler = clusterApiHandler() processor = clusterApi.Processor(handler) transport = TSocket.TServerSocket(hostIp, thd_port.THRIFT_CC_PORT) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() #server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) # You could do one of these for a multithreaded server #server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory) logger.info('Starting cluster the server...') server.serve() logger.error('thrift cluster server quit!') break else: time.sleep(DEFAULT_DELAY) else: time.sleep(DEFAULT_DELAY)
def run(self): while True: logger.info('p_get_ip_thread...start') global g_clc_ip global g_wal_ip g_wal_ip = utility.get_local_publicip() ldap_ip = utility.get_ldap_server() ret = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_WALRUS,g_wal_ip) if ret: g_clc_ip = OpenLdap.get_clc_ip(ldap_ip) if (g_clc_ip != None) and (g_wal_ip != None): break else: logger.info('p_get_ip_thread()') time.sleep(1)
def p_register_cluster(): hostIp = utility.get_local_publicip() while True: ldap_ip = utility.get_ldap_server() # avoid the ip address cant be read if ldap_ip!=None: clusterInfo = OpenLdap.p_get_clusterInfo_by_ccIp(ldap_ip,hostIp) if clusterInfo!=None: if clusterInfo.clusterName==None : ccName = p_get_cc_name_conf() if ccName!=None: OpenLdap.p_register_cluster(ldap_ip,ccName,hostIp) else: break else: break time.sleep(DEFAULT_DELAY)
def run(self): while True: walrusIp = utility.get_local_publicip() if walrusIp!=None: ldap_ip = utility.get_ldap_server() ret = OpenLdap.p_init_walrus_info(ldap_ip,walrusIp) if ret: break time.sleep(1)
def run(self): while True: ldap_ip = utility.get_ldap_server() ret = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_WALRUS,utility.get_local_publicip()) if ret: logger.debug('p_heart_beat_thread start ...') p_heart_beat_timer() break else: time.sleep(2)
def run(self): while True: ldap_ip = utility.get_ldap_server() ret = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_CC,utility.get_local_publicip()) if ret: p_nc_heart_beat_isAlive() p_heart_beat_timer() break else: time.sleep(DEFAULT_DELAY)
def run(self): while True: logger.debug('p_get_ip_thread...start') global g_clc_ip global g_cc_ip g_cc_ip = utility.get_local_publicip() ldap_ip = utility.get_ldap_server() # avoid the ip address cant be read if ldap_ip!=None: ret = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_CC,g_cc_ip) if ret: ldap_ip = utility.get_ldap_server() g_clc_ip = OpenLdap.get_clc_ip(ldap_ip) if (g_clc_ip != None) and (g_cc_ip != None): logger.info('g_cc_ip:%s,g_clc_ip:%s' %(g_cc_ip,g_clc_ip)) break else: logger.debug('waiting in p_get_ip_thread()!!!') time.sleep(DEFAULT_DELAY)
def p_nc_heart_beat(ncIp): global g_nc_heart_beat ret = True if not g_nc_heart_beat.has_key(ncIp): ldap_ip = utility.get_ldap_server() re = OpenLdap.p_is_register(ldap_ip,thd_SERVICE_TYPE.CLOUD_NC,ncIp) if re: g_nc_heart_beat[ncIp] = time.time() else: ret = False else: g_nc_heart_beat[ncIp] = time.time() return ret
def luhya_clc_stop_vm(self, clientInfo): """ harrison 如果是在线并且是远程模式: 转发调用ClcThriftServer API luhya_clc_stop_vm(client_info)停止虚拟机 如果是在线本地模式或离线模式: 直接调用NcThriftServer API luhya_nc_stop_vm(client_info)停止虚拟机 """ ret = False if clientInfo.instance_state.is_local: local_nc_ip = utility.get_local_publicip() if local_nc_ip != None: ret = OpenLdap.p_nc_stop_vm(local_nc_ip, clientInfo) else: ldap_ip = utility.get_real_ldap() if ldap_ip != None: clc_ip = OpenLdap.get_clc_ip(ldap_ip) if clc_ip != None: ret = OpenLdap.clc_stop_vm(clc_ip, clientInfo) else: logger.debug("get real clc ip is error!") else: logger.debug("get real ldap ip is error!") return ret
def run(self): logger.debug('p_transmit_server_source_thread...') global g_nc_source global g_cc_ip global g_clc_ip while True: hdSource = utility.utility_get_current_resource() g_source_switch.acquire() hdSource.net_receiverate = g_server_resource['recvRate'] hdSource.net_sendrate = g_server_resource['sendRate'] hdSource.cpu_utilization = g_server_resource['cpuUtilization'] g_source_switch.release() hdSource.state = 'HW_STATUS_OK' if hdSource.cpu_utilization > VM_CPU_UTILIZATION: hdSource.state = 'HW_STATUS_WARN' if g_cc_ip!=None: g_nc_source[g_cc_ip] = hdSource logger.info(g_nc_source) nc_source = g_nc_source.copy() for ip in nc_source: if g_clc_ip!=None: OpenLdap.p_transmit_hard_source(g_clc_ip,ip,nc_source[ip]) time.sleep(SERVER_SOURCE_INTV)
def p_start_vm(clientInfo): nodeIp = None ret = 0 if clientInfo.is_assign_node!=None and clientInfo.is_assign_node: nodeIp = clientInfo.node_ip else: nodeIp = p_dispatch_nodes() if nodeIp!=None: logger.debug('p_start_vm node:%s' %nodeIp) ret = OpenLdap.p_nc_start_vm(nodeIp,clientInfo) else: ret = -7 retInfo = thd_run_instance_ret() retInfo.node_ip = nodeIp retInfo.return_value = ret logger.debug('p_start_vm the return value:%s' %str(retInfo)) return retInfo
def _is_online(): ret = False ldap_ip = utility.get_ldap_server() if ldap_ip != None: ret = OpenLdap.p_ldap_online(ldap_ip) return ret
def p_get_client_data(user, requestIp): client_infos = [] if _is_online(): logger.info("real clc is online") local_ip = utility.get_local_publicip() if local_ip != None: real_ldap_ip = utility.get_real_ldap() logger.info("real ldap ip:%s" % real_ldap_ip) if real_ldap_ip != None: clc_ip = OpenLdap.get_clc_ip(real_ldap_ip) client_infos = OpenLdap.get_client_data(clc_ip, user, local_ip) realUser = user if user != "super": _save_client_infos(user, client_infos) else: realUser = "******" # update local instance state instances = OpenLdap.get_instance_states(local_ip, realUser) for client_info in client_infos: if user == "super" and client_info.node_ip == local_ip: client_info.run_as_super = True else: client_info.run_as_super = False find_client_info = False for instance in instances: if ( client_info.node_ip == local_ip and instance.user == client_info.user and instance.image_id == client_info.image_id ): find_client_info = True client_info.instance_state.state = instance.state client_info.vm_info.vm_port = instance.n_port client_info.vm_info.vm_password = instance.str_password break if not find_client_info and client_info.node_ip == local_ip: client_info.instance_state.state = thd_TRANSACT_STATE.TERMINATED else: logger.error("p_get_client_data: real ldap ip error") else: logger.error("p_get_client_data: get local ip error") else: logger.info("real clc not online") local_ip = utility.get_local_publicip() if user == "super": logon_users = _get_logon_users() logger.info("logon user: %s" % str(logon_users)) for usrName in logon_users: local_client = _read_client_infos(usrName) for lcClient in local_client: if lcClient.vm_info.is_clear_power_off: client_infos.append(lcClient) else: client_infos = _read_client_infos(user) logger.info("the saved client info number : %d " % len(client_infos)) realUser = user if user == "super": realUser = "******" instances = OpenLdap.get_instance_states(local_ip, realUser) logger.info("the instance: %s" % str(instances)) for client_info in client_infos: if user == "super": client_info.run_as_super = True else: client_info.run_as_super = False if not client_info.instance_state.is_local: # remote instance can not be run client_info.instance_state.is_can_run = False client_info.instance_state.state = thd_TRANSACT_STATE.TERMINATED else: if _image_cache_exist(client_info.image_id, client_info.image_size): # the image is cached client_info.instance_state.is_can_run = True else: client_info.instance_state.is_can_run = False find_client_info = False for instance in instances: if ( client_info.instance_state.is_local and instance.user == client_info.user and instance.image_id == client_info.image_id ): find_client_info = True client_info.instance_state.state = instance.state client_info.vm_info.vm_port = instance.n_port client_info.vm_info.vm_password = instance.str_password break if not find_client_info: client_info.instance_state.state = thd_TRANSACT_STATE.TERMINATED logger.debug("p_get_client_data: %s" % str(client_infos)) return client_infos