def bundle_status_cb(self,buf, cmdtimeout, parttimeout, starttime,lasttime, check_image_stage): #self.debug('bundle_status_cb: cmdtimeout:'+str(cmdtimeout)+", partimeout:"+str(parttimeout)+", starttime:"+str(starttime)+", lasttime:"+str(lasttime)+", check_image_stage:"+str(check_image_stage)) ret = SshCbReturn(stop=False) #if the over timeout or the callback interval has expired, then return stop=true #interval timeout should not be hit due to the setting of the timer value, but check here anyways if (cmdtimeout != 0) and ( int(time.time()-starttime) > cmdtimeout): self.debug('bundle_status_cb command timed out after '+str(cmdtimeout)+' seconds') ret.statuscode=-100 ret.stop = True return ret if not check_image_stage: ret.settimer = parttimeout if (parttimeout != 0 and lasttime != 0) and (int(time.time()-lasttime) > parttimeout): self.debug('bundle_status_cb inter-part time out after '+str(parttimeout)+' seconds') ret.statuscode=-100 ret.stop = True return ret if re.search('[P|p]art:',buf): sys.stdout.write("\r\x1b[K"+str(buf).strip()) sys.stdout.flush() check_image_stage=False else: #Print command output and write to ssh.cmd['output'] buffer ret.buf = buf self.debug(str(buf)) #Command is still going, reset timer thread to intervaltimeout, provide arguments for next time this is called from ssh cmd. ret.stop = False ret.nextargs =[cmdtimeout,parttimeout,starttime,time.time(),check_image_stage] return ret
def _raw_cb(self, buf, promptcount, promptstring, promptmax, debug): ''' Call back which can be used to control and ssh command when a shell and raw input needed (ie to send controlled tabs for example) param buf: buffer provided by ssh.cmd session param promptcount: int amount of times we've seen the prompt param promptstring: string the string to match param promptmax: the maximum number prompt matches before the command is signaled 'done' returns SshCbReturn obj ''' ret = SshCbReturn(buf=buf, stop=False) #Count the number of occurrences of the promptstring promptcount = promptcount + len(re.findall(promptstring,buf)) if promptcount >= promptmax: ret.stop = True #Return the args this call back will be called with the next time around ret.nextargs=[promptcount, promptstring, promptmax, debug] if debug: print str(buf)+ '\npromptcount:' + str(promptcount) + ', promptstring:' + str(promptstring) + ', promptmax:'+ str(promptmax) return ret
def _raw_cb(self, buf, promptcount, promptstring, promptmax, debug): ''' Call back which can be used to control and ssh command when a shell and raw input needed (ie to send controlled tabs for example) param buf: buffer provided by ssh.cmd session param promptcount: int amount of times we've seen the prompt param promptstring: string the string to match param promptmax: the maximum number prompt matches before the command is signaled 'done' returns SshCbReturn obj ''' ret = SshCbReturn(buf=buf, stop=False) #Count the number of occurrences of the promptstring promptcount = promptcount + len(re.findall(promptstring, buf)) if promptcount >= promptmax: ret.stop = True #Return the args this call back will be called with the next time around ret.nextargs = [promptcount, promptstring, promptmax, debug] if debug: print str(buf) + '\npromptcount:' + str( promptcount) + ', promptstring:' + str( promptstring) + ', promptmax:' + str(promptmax) return ret