Exemplo n.º 1
0
    def _doParallelOperate(self, hostSet, cmd, parallel, remoteTimeout, retryTime,
                           retryInterval, user, remoteSudo, errorContinue):
        successList = []
        failedList = []
        if not hostSet:
            return successList, failedList

        count = 0
        hostLen = len(hostSet)
        threaderList = []
        for host in hostSet:
            Log.coutLabel(Log.INFO, 'Process Remote host:%s' % host)
            remoteCmd = 'ssh %s@%s %s' % (user, host, cmd)
            threader = RemoteOperatorThread(host, self._ainstBinPath, remoteCmd,
                                            remoteTimeout, retryTime,
                                            retryInterval, user, remoteSudo)
            threader.setDaemon(True)
            threaderList.append(threader)
            threader.start()
            count += 1
            if count % parallel != 0 and count < hostLen:
                continue
            
            for threader in threaderList:
                threader.join()
            for threader in threaderList:
                if not threader.returnValue:
                    failedList.append(threader.host)
                else:
                    successList.append(threader.host)
            if not errorContinue and len(failedList) > 0:
                break
            threaderList = []

        return successList, failedList
Exemplo n.º 2
0
    def _doParallelOperate(self, hostSet, cmd, parallel, remoteTimeout,
                           retryTime, retryInterval, user, remoteSudo,
                           errorContinue):
        successList = []
        failedList = []
        if not hostSet:
            return successList, failedList

        count = 0
        hostLen = len(hostSet)
        threaderList = []
        for host in hostSet:
            Log.coutLabel(Log.INFO, 'Process Remote host:%s' % host)
            remoteCmd = 'ssh %s@%s %s' % (user, host, cmd)
            threader = RemoteOperatorThread(host, self._ainstBinPath,
                                            remoteCmd, remoteTimeout,
                                            retryTime, retryInterval, user,
                                            remoteSudo)
            threader.setDaemon(True)
            threaderList.append(threader)
            threader.start()
            count += 1
            if count % parallel != 0 and count < hostLen:
                continue

            for threader in threaderList:
                threader.join()
            for threader in threaderList:
                if not threader.returnValue:
                    failedList.append(threader.host)
                else:
                    successList.append(threader.host)
            if not errorContinue and len(failedList) > 0:
                break
            threaderList = []

        return successList, failedList
Exemplo n.º 3
0
    def remoteOperate(self,
                      param,
                      command,
                      installRoot=None,
                      confirmYes=False):
        if param.remoteTimeout < 0 or param.retryInterval < 0:
            Log.cout(Log.ERROR, 'Remote param is invalid')
            return False

        if param.remoteBin:
            self._ainstBinPath = param.remoteBin

        hostSet = self._getHostSet(param.host, param.hostFile)
        if hostSet:
            hostSet = set([x for x in hostSet if x and x.strip()])
        if not hostSet:
            Log.cout(Log.ERROR, 'No valid ip or host')
            return False

        user = param.remoteUser
        if not user:
            user = getpass.getuser()
        cmd = self._generateRemoteCmd(command, confirmYes, installRoot,
                                      param.remoteConf)
        if param.remoteSudo:
            cmd = 'sudo %s' % cmd

        Log.coutLabel(Log.INFO, 'Process total %d remote host' % len(hostSet))
        parallel = self._getParallelCount(param.parallel)
        successList, failedList =\
            self._doParallelOperate(hostSet, cmd, parallel, param.remoteTimeout,
                                    param.retryTime, param.retryInterval,
                                    user, param.remoteSudo, param.errorContinue)

        Log.coutLabel(Log.INFO, 'Process remote host total(%d), success(%d), failed(%d)'\
                          % (len(hostSet), len(successList), len(failedList)))
        for success in successList:
            Log.coutValue(Log.INFO, success, 'success')
        for failed in failedList:
            Log.coutValue(Log.INFO, failed, 'failed')
        Log.coutLabel(Log.INFO, 'end')
        if len(failedList) > 0:
            return False
        return True
Exemplo n.º 4
0
    def remoteOperate(self, param, command, installRoot=None, confirmYes=False):
        if param.remoteTimeout < 0 or param.retryInterval < 0:
            Log.cout(Log.ERROR, 'Remote param is invalid')
            return False

        if param.remoteBin:
            self._ainstBinPath = param.remoteBin

        hostSet = self._getHostSet(param.host, param.hostFile)
        if hostSet:
            hostSet = set([x for x in hostSet if x and x.strip()])
        if not hostSet:
            Log.cout(Log.ERROR, 'No valid ip or host')
            return False

        user = param.remoteUser
        if not user:
            user = getpass.getuser()
        cmd = self._generateRemoteCmd(command, confirmYes, installRoot,
                                      param.remoteConf)
        if param.remoteSudo:
            cmd = 'sudo %s' % cmd

        Log.coutLabel(Log.INFO, 'Process total %d remote host' % len(hostSet))
        parallel = self._getParallelCount(param.parallel)
        successList, failedList =\
            self._doParallelOperate(hostSet, cmd, parallel, param.remoteTimeout,
                                    param.retryTime, param.retryInterval,
                                    user, param.remoteSudo, param.errorContinue)

        Log.coutLabel(Log.INFO, 'Process remote host total(%d), success(%d), failed(%d)'\
                          % (len(hostSet), len(successList), len(failedList)))
        for success in successList:
            Log.coutValue(Log.INFO, success, 'success')
        for failed in failedList:
            Log.coutValue(Log.INFO, failed, 'failed')
        Log.coutLabel(Log.INFO, 'end')
        if len(failedList) > 0:
            return False
        return True