Esempio n. 1
0
 def get_file(self, remote_path, local_path):
     logger.info(
         "Receiving from {host}:[{remote}] to [{local}]".format(
             local=local_path, host=self.host, remote=remote_path))
     with self.connect() as client, client.open_sftp() as sftp:
         result = sftp.get(remote_path, local_path)
     return result
Esempio n. 2
0
 def send_file(self, local_path, remote_path):
     logger.info(
         "Sending [{local}] to {host}:[{remote}]".format(
             local=local_path, host=self.host, remote=remote_path))
     with self.connect() as client, client.open_sftp() as sftp:
         result = sftp.put(local_path, remote_path)
     return result
Esempio n. 3
0
def check_ssh_connection():
    logging.basicConfig(
        level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
    logging.getLogger("paramiko.transport").setLevel(logging.DEBUG)

    parser = argparse.ArgumentParser(
        description='Test SSH connection for monitoring.')
    parser.add_argument(
        '-e', '--endpoint', default='example.org', help='which host to try')

    parser.add_argument(
        '-u', '--username', default=pwd.getpwuid(os.getuid())[0], help='SSH username')

    parser.add_argument('-p', '--port', default=22, type=int, help='SSH port')
    args = parser.parse_args()
    logging.info(
        "Checking SSH to %s@%s:%d", args.username, args.endpoint, args.port)
    ssh = SecuredShell(args.endpoint, args.port, args.username, 10)
    data = ssh.execute("ls -l")
    logging.info('Output data of ssh.execute("ls -l"): %s', data[0])
    logging.info('Output errors of ssh.execute("ls -l"): %s', data[1])
    logging.info('Output code of ssh.execute("ls -l"): %s', data[2])

    logging.info('Trying to create paramiko ssh connection client')
    client = ssh.connect()
    logging.info('Created paramiko ssh connection client: %s', client)
    logging.info('Trying to open sftp')
    sftp = client.open_sftp()
    logging.info('Opened sftp: %s', sftp)
    logging.info('Trying to send test file to /tmp')
    res = sftp.put('/usr/lib/yandex/yandex-tank/bin/tank.log', '/opt')
    logging.info('Result of sending test file: %s', res)
Esempio n. 4
0
 def get_file(self, remote_path, local_path):
     logger.info(
         "Receiving from {host}:[{remote}] to [{local}]".format(
             local=local_path, host=self.host, remote=remote_path))
     with self.connect() as client, client.open_sftp() as sftp:
         result = sftp.get(remote_path, local_path)
     return result
Esempio n. 5
0
def check_ssh_connection():
    logging.basicConfig(
        level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
    logging.getLogger("paramiko.transport").setLevel(logging.DEBUG)

    parser = argparse.ArgumentParser(
        description='Test SSH connection for monitoring.')
    parser.add_argument(
        '-e', '--endpoint', default='example.org', help='which host to try')

    parser.add_argument(
        '-u', '--username', default=pwd.getpwuid(os.getuid())[0], help='SSH username')

    parser.add_argument('-p', '--port', default=22, type=int, help='SSH port')
    args = parser.parse_args()
    logging.info(
        "Checking SSH to %s@%s:%d", args.username, args.endpoint, args.port)
    ssh = SecuredShell(args.endpoint, args.port, args.username, 10)
    data = ssh.execute("ls -l")
    logging.info('Output data of ssh.execute("ls -l"): %s', data[0])
    logging.info('Output errors of ssh.execute("ls -l"): %s', data[1])
    logging.info('Output code of ssh.execute("ls -l"): %s', data[2])

    logging.info('Trying to create paramiko ssh connection client')
    client = ssh.connect()
    logging.info('Created paramiko ssh connection client: %s', client)
    logging.info('Trying to open sftp')
    sftp = client.open_sftp()
    logging.info('Opened sftp: %s', sftp)
    logging.info('Trying to send test file to /tmp')
    res = sftp.put('/usr/lib/yandex/yandex-tank/bin/tank.log', '/opt')
    logging.info('Result of sending test file: %s', res)
Esempio n. 6
0
    def send_file(self, local_path, remote_path):
        logger.info(
            "Sending [{local}] to {host}:[{remote}]".format(
                local=local_path, host=self.host, remote=remote_path))

        with self.connect() as client, client.open_sftp() as sftp:
            result = sftp.put(local_path, remote_path)
        return result