def exeShellCmd(varBlob):
        #if varBlob.get('help', None):
        #    raise CMException(
        #        """
        #            suboptions for --task=exeShellCmd
        #            --cmd=<bash shell cmd>
        #        """
        #    )
        if not varBlob.get('cmd', None):
            raise CMException('must provide --cmd=SHELL_CMD')

        # get all hostSets
        confDict = Utils.getDictFromFile(projConst.cusConfPath)
        hostSets = DictAddrReader.readByPath("hostSets", confDict)
        hostSets = hostSets.items()
 
        targetHostSets = varBlob.get('envs', None)
        if targetHostSets:
            targetHostSets = targetHostSets.split(',')
            hostSets = filter(lambda (env, envData,): env in targetHostSets, hostSets)
       
        num_cores = multiprocessing.cpu_count()
        for env, envData in hostSets:
            port = DictAddrReader.readByPath("port", envData)
            sshKeyPath = DictAddrReader.readByPath("sshKeyPath", envData)
            ipList = DictAddrReader.readByPath("ipList", envData).split(',')
            Parallel(n_jobs=num_cores)(delayed(executeShellCmd)({'ip': ip, 'port': port, 'sshKeyPath': sshKeyPath, 'cmd': varBlob['cmd'],}) for ip in ipList)
def main():
    
    # get all hostSets
    confDict = Utils.getDictFromFile(projConst.cusConfPath)
    hostSets = DictAddrReader.readByPath("hostSets", confDict)
    num_cores = multiprocessing.cpu_count()
    for env, envData in hostSets.items():
        port = DictAddrReader.readByPath("port", envData)
        sshKeyPath = DictAddrReader.readByPath("sshKeyPath", envData)
        ipList = DictAddrReader.readByPath("ipList", envData).split(',')
        pushFileAbsPath, pushFileName = createBundleToSlave(env, envData)
        Parallel(n_jobs=num_cores)(delayed(process)(ip, port, sshKeyPath, pushFileAbsPath, pushFileName) for ip in ipList)
 def initDebianSlave(varBlob):
     #if varBlob.get('help', None):
     #    raise CMException()
     # get all hostSets
     confDict = Utils.getDictFromFile(projConst.cusConfPath)
     hostSets = DictAddrReader.readByPath("hostSets", confDict)
     num_cores = multiprocessing.cpu_count()
     for env, envData in hostSets.items():
         port = DictAddrReader.readByPath("port", envData)
         sshKeyPath = DictAddrReader.readByPath("sshKeyPath", envData)
         ipList = DictAddrReader.readByPath("ipList", envData).split(',')
         Parallel(n_jobs=num_cores)(delayed(executeShellCmd)({'ip': ip, 'port': port, 'sshKeyPath': sshKeyPath, 'cmd': projConst.cmdTemplate['init_debian_slave']}) for ip in ipList)        
 def connectionTest(varBlob):
     #if varBlob.get('help', None):
     #    raise CMException()
     # get all hostSets
     confDict = Utils.getDictFromFile(projConst.cusConfPath)
     hostSets = DictAddrReader.readByPath("hostSets", confDict)
     num_cores = multiprocessing.cpu_count()
     for env, envData in hostSets.items():
         port = DictAddrReader.readByPath("port", envData)
         sshKeyPath = DictAddrReader.readByPath("sshKeyPath", envData)
         ipList = DictAddrReader.readByPath("ipList", envData).split(',')
         Parallel(n_jobs=num_cores)(delayed(_connectionTest)(ip, port, sshKeyPath) for ip in ipList)
def createBundleToSlave(env, envData):
    keyBelongsGroups = map(lambda group: group + "_*.pub", DictAddrReader.readByPath("groupList", envData).split(','))
    planToShipFiles = keyBelongsGroups + projConst.fileToShip.split(',')
    findExp = Utils.findExpConstructFromList(planToShipFiles)

    slaveConfAbsPath = Utils.recoverStringByDict(projConst.confTemplate['slaveConfAbsPath'], {"HOSTSET": env, })
    Utils.flushDictToFile(
        {'env': env,
         'envData': envData
        }
        , slaveConfAbsPath)

    pushFileAbsPath = Utils.recoverStringByDict(projConst.confTemplate['pushFileAbsPath'], {"EXPS": findExp, "HOSTSET": env, })
    pushFileName = Utils.recoverStringByDict(projConst.confTemplate['pushFileName'], {"HOSTSET": env, })

    tar_to_ship_CMD = Utils.recoverStringByDict(projConst.cmdTemplate['tar_to_ship'], {"EXPS": findExp, "FILE": pushFileAbsPath,})
    ShellCmdExecutor.executeSync(tar_to_ship_CMD)
    
    return (pushFileAbsPath, pushFileName,)