def __init__(self, name, aspdir, ip, user, password, logdir="."): self.name = name self.ip = ip self.user = user self.password = password self.asp_dir = aspdir if 1: logfilename = logdir + os.sep + "ssh_" + self.name + ".log" retries = 0 while retries < 4: retries += 1 tgtexp = pxssh.pxssh() fout = open(logfilename, "w") tgtexp.logfile = fout try: result = tgtexp.login(self.ip, self.user, self.password, login_timeout=30) retries = 10000 except pxssh.ExceptionPxssh, e: # Could not synchronize with original prompt if retries > 3: raise misc.Error("Cannot connect to %s exception: %s" % (self.ip, str(e))) if not result: raise misc.Error("Cannot connect to %s" % self.ip) tgtexp.setwinsize(200, 1024) tgtexp.delaybeforesend = 0 # to make sessions a lot faster tgtexp.sendline("export PS1='_tgtexpectprompt_$ '") psh.Psh.__init__(self, tgtexp, re.escape("_tgtexpectprompt_$ ")) self.bash = self # for compatibility with other object hierarchies
def copyApp(fromdir, to, appDir=None): "Private: Copy application files to the other blades" logdir = os.getenv("ASP_LOGDIR") if logdir: logFileName = logdir + os.sep + 'appdeploy.log' else: logFileName = 'appdeploy.log' try: fout = file(logFileName, 'w+') except: # lack of debug logging should not be fatal fout = None exp = pexpect.spawn('bash') exp.delaybeforesend = 0 # to make sessions a lot faster i = exp.expect([pexpect.TIMEOUT, '[$#>]'], timeout=10) if i == 0: # timeout raise DeployError("Could not start bash session") exp.setwinsize(200, 1024) exp.logfile = fout exp.sendline("export PS1='_expectpromptlocal_'") pshell = psh.Psh(exp, '_expectpromptlocal_') # the "to" argument can be a string containing the node name, slot number or IP address, OR it can be an AmfNodeEntity if type(to) is type(""): node = clusterinfo.ci.nodes[to] else: node = to try: fout2 = file(logFileName + "1", 'w+') except: fout2 = None retries = 0 while retries < 4: retries += 1 tgtexp = pxssh.pxssh() tgtexp.logfile = fout2 log.info("Connecting to %s user %s pw %s" % (node.localIp, node.localUser, node.localPasswd)) try: result = tgtexp.login(node.localIp, node.localUser, node.localPasswd, login_timeout=30) retries = 10000 except pxssh.ExceptionPxssh, e: # Could not synchronize with original prompt if retries > 3: raise DeployError("Cannot connect to %s exception: %s" % (node.localIp, str(e)))
def copyApp(fromdir,to,appDir=None): "Private: Copy application files to the other blades" logdir = os.getenv("ASP_LOGDIR") if logdir: logFileName = logdir + os.sep + 'appdeploy.log' else: logFileName = 'appdeploy.log' try: fout = file(logFileName, 'w+') except: # lack of debug logging should not be fatal fout = None exp = pexpect.spawn('bash') exp.delaybeforesend = 0 # to make sessions a lot faster i = exp.expect([pexpect.TIMEOUT, '[$#>]'], timeout=10) if i==0: # timeout raise DeployError("Could not start bash session") exp.setwinsize(200, 1024) exp.logfile = fout exp.sendline("export PS1='_expectpromptlocal_'") pshell = psh.Psh(exp, '_expectpromptlocal_') # the "to" argument can be a string containing the node name, slot number or IP address, OR it can be an AmfNodeEntity if type(to) is type(""): node = clusterinfo.ci.nodes[to] else: node = to try: fout2 = file(logFileName + "1", 'w+') except: fout2 = None retries = 0 while retries<4: retries += 1 tgtexp = pxssh.pxssh() tgtexp.logfile = fout2 log.info("Connecting to %s user %s pw %s" % (node.localIp, node.localUser, node.localPasswd)) try: result = tgtexp.login(node.localIp, node.localUser, node.localPasswd, login_timeout=30) retries = 10000 except pxssh.ExceptionPxssh,e: # Could not synchronize with original prompt if retries>3: raise DeployError("Cannot connect to %s exception: %s" % (node.localIp,str(e)))