Beispiel #1
0
    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:
         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)   
Beispiel #3
0
 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 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)
Beispiel #6
0
 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.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)
Beispiel #8
0
 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()!!!')
Beispiel #9
0
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)
Beispiel #10
0
    def run(self):
        logger.info("g_ClcThriftServer_main_interface running ...")
        handler = clcApiHandler()
        processor = clcApi.Processor(handler)

        transport = TSocket.TServerSocket(utility.get_local_publicip(), thd_port.THRIFT_CLC_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 quit!")
Beispiel #11
0
 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)
Beispiel #12
0
 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
Beispiel #13
0
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