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)
Exemple #2
0
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 !")
Exemple #3
0
 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()]
Exemple #4
0
 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()]
Exemple #5
0
# 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
Exemple #6
0
 def test_enabling_pssh_logger(self):
     utils.enable_logger(utils.logger)
     self.assertTrue(len(utils.logger.handlers) == 1)
Exemple #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
Exemple #8
0
 def test_enabling_pssh_logger(self):
     utils.enable_logger(utils.logger)
     self.assertTrue(len(utils.logger.handlers)==1)
Exemple #9
0
#!/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)
Exemple #10
0
def initialize_client(hosts, key):
    enable_logger(logger)
    return ParallelSSHClient(hosts, user = '******', pkey = key)