def reset_guacamole_client(): session = DBSession() query = session.query(GuacamoleClientInfo) #If I can add another condition for query to lock with update, for example, query.filter(GuacamoleClientInfo.guacamole_client_host=='').filter....... #Then this process can be more fine-grained result = query.filter(GuacamoleClientInfo.status==1).filter(GuacamoleClientInfo.user_info!='').with_lockmode('update').all() if result==None: return cur_time = datetime.now() for res in result: seconds = __time_diff(cur_time,res.latest_active_timestamp) if seconds>=client_time_limit: guacamole_client_vm = res.guacamole_client_vm guacamole_client_host = res.guacamole_client_host image = res.image res.user_info = '' res.status = 0 res.image = '' protocol = res.protocol guacamole_server = res.guacamole_server query = session.query(GuacamoleServerLoad) result = query.filter(GuacamoleServerLoad.guacamole_server == guacamole_server).with_lockmode('update').first() result = __server_protocol_update(protocol,-1,result) signal = containerservice.shutdown_container(guacamole_client_vm,int(guacamole_client_host[guacamole_client_host.index(':')+1:]),image) if signal==False: #Record this error pass session.commit() session.close()
def shutdown_guacamole_client(client_id, image,protocol,mylog): guacamole_client_host,guacamole_client_vm = cancel_guacamole_client(client_id, image, protocol) if guacamole_client_host==None: return signal = containerservice.shutdown_container(guacamole_client_vm,int(guacamole_client_host[guacamole_client_host.index(':')+1:]),image) if signal==False: mylog.info("shutdown a container failed...") pass
def shutdown_guacamole_client(client_id, image, protocol, mylog): guacamole_client_host, guacamole_client_vm = cancel_guacamole_client( client_id, image, protocol) if guacamole_client_host == None: return signal = containerservice.shutdown_container( guacamole_client_vm, int(guacamole_client_host[guacamole_client_host.index(':') + 1:]), image) if signal == False: mylog.info("shutdown a container failed...") pass
def reset_guacamole_client(): session = DBSession() query = session.query(GuacamoleClientInfo) #If I can add another condition for query to lock with update, for example, query.filter(GuacamoleClientInfo.guacamole_client_host=='').filter....... #Then this process can be more fine-grained result = query.filter(GuacamoleClientInfo.status == 1).filter( GuacamoleClientInfo.user_info != '').with_lockmode('update').all() if result == None: return cur_time = datetime.now() for res in result: seconds = __time_diff(cur_time, res.latest_active_timestamp) if seconds >= client_time_limit: guacamole_client_vm = res.guacamole_client_vm guacamole_client_host = res.guacamole_client_host image = res.image res.user_info = '' res.status = 0 res.image = '' protocol = res.protocol guacamole_server = res.guacamole_server query = session.query(GuacamoleServerLoad) result = query.filter( GuacamoleServerLoad.guacamole_server == guacamole_server).with_lockmode('update').first() result = __server_protocol_update(protocol, -1, result) signal = containerservice.shutdown_container( guacamole_client_vm, int(guacamole_client_host[guacamole_client_host.index(':') + 1:]), image) if signal == False: #Record this error pass session.commit() session.close()