コード例 #1
0
    def __init__(self, config_ssh, groups, verbose=False):
        self.config_ssh = config_ssh
        self.groups = groups
        self.verbose = verbose

        if self.verbose:
            utils.enable_logger(utils.logger)
コード例 #2
0
ファイル: pssh_run.py プロジェクト: niyoh120/pssh
def main():
    """
        main
    """
    config = parse_json('config.json')
    logging.basicConfig(level=logging.INFO, filename='log.log', filemode='w')
    utils.enable_logger(utils.logger)

    global CONFIRM
    CONFIRM = config.get('confirm', False)

    for cf in config.get('tasks', []):
        config = parse_json(cf)
        ip_list = []

        timer = config.get('timer', 0)
        for n in range(timer):
            print('wating {:04}s to run task [{}]\r'.format(timer - n, cf),
                  end='')
            time.sleep(1)
        else:
            print()
        for ip_str in config.get('ping', []):
            ip_list.extend(find_ip(parse_ip(ip_str)))
        if exec_pssh(config, ip_list):
            utils.logger.info("[{}] succeed !".format(cf))
        else:
            utils.logger.warning("[{}] failed !")
コード例 #3
0
ファイル: test_utils.py プロジェクト: Tysher/parallel-ssh
 def test_enabling_pssh_logger(self):
     self.assertTrue(len([h for h in utils.logger.handlers
                          if isinstance(h, NullHandler)]) == 1)
     utils.enable_logger(utils.logger)
     utils.enable_logger(utils.logger)
     self.assertTrue(len([h for h in utils.logger.handlers
                          if not isinstance(h, NullHandler)]) == 1)
     utils.logger.handlers = [NullHandler()]
コード例 #4
0
ファイル: test_utils.py プロジェクト: pkittenis/parallel-ssh
 def test_enabling_pssh_logger(self):
     self.assertTrue(len([h for h in utils.logger.handlers
                          if isinstance(h, NullHandler)]) == 1)
     utils.enable_logger(utils.logger)
     utils.enable_logger(utils.logger)
     self.assertTrue(len([h for h in utils.logger.handlers
                          if not isinstance(h, NullHandler)]) == 1)
     utils.logger.handlers = [NullHandler()]
コード例 #5
0
ファイル: pssh_local.py プロジェクト: UniqueLJH/parallel-ssh
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

"""Connect to SSH server on localhost,
attempt to perform an `ls` and copy a test file with both SSHClient
and ParallelSSHClient.
"""

from pssh import SSHClient, ParallelSSHClient, utils
import logging
from pprint import pprint

utils.enable_host_logger()
utils.enable_logger(utils.logger)

def test():
    """Perform ls and copy file with SSHClient on localhost"""
    client = SSHClient('localhost')
    channel, host, stdout, stderr = client.exec_command('ls -ltrh')
    for line in stdout:
        pprint(line.strip())
    client.copy_file('../test', 'test_dir/test')

def test_parallel():
    """Perform ls and copy file with ParallelSSHClient on localhost.
    
    Two identical hosts cause the same command to be executed
    twice on the same host in two parallel connections.
    In printed output there will be two identical lines per printed per
コード例 #6
0
ファイル: test_utils.py プロジェクト: kyle-mt/parallel-ssh
 def test_enabling_pssh_logger(self):
     utils.enable_logger(utils.logger)
     self.assertTrue(len(utils.logger.handlers) == 1)
コード例 #7
0
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"""Connect to SSH server on localhost,
attempt to perform an `ls` and copy a test file with both SSHClient
and ParallelSSHClient.
"""

from pssh import SSHClient, ParallelSSHClient, utils
import logging
from pprint import pprint

utils.enable_host_logger()
utils.enable_logger(utils.logger)


def test():
    """Perform ls and copy file with SSHClient on localhost"""
    client = SSHClient('localhost')
    channel, host, stdout, stderr = client.exec_command('ls -ltrh')
    for line in stdout:
        pprint(line.strip())
    client.copy_file('../test', 'test_dir/test')


def test_parallel():
    """Perform ls and copy file with ParallelSSHClient on localhost.
    
    Two identical hosts cause the same command to be executed
コード例 #8
0
ファイル: test_utils.py プロジェクト: UniqueLJH/parallel-ssh
 def test_enabling_pssh_logger(self):
     utils.enable_logger(utils.logger)
     self.assertTrue(len(utils.logger.handlers)==1)
コード例 #9
0
ファイル: ssh.py プロジェクト: leisheyoufu/study_exercise
#!/usr/bin/env python
from __future__ import print_function

from pssh.pssh_client import ParallelSSHClient
from pssh.utils import enable_logger, logger
from gevent import joinall

enable_logger(logger)
hosts = ['9.114.120.103']
client = ParallelSSHClient(hosts, user='******', pkey='xxx')
cmds = client.copy_file('/tmp/test.txt', '/tmp/test.txt')
joinall(cmds, raise_error=True)
コード例 #10
0
ファイル: main.py プロジェクト: nstudach/sugar
def initialize_client(hosts, key):
    enable_logger(logger)
    return ParallelSSHClient(hosts, user = '******', pkey = key)