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: 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 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 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 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