예제 #1
0
파일: main.py 프로젝트: MartinSolie/mcduck
def ssh(connection_string, command, identity, port, rpass, rphrase,
        command_args):
    """Will execute COMMAND via ssh

    Please pass CONNECTION_STRING in the followin format:
    [username[:password]@]<host>

    COMMAND: command to execute

    COMMAND_ARGS: params, passed to COMMAND, please prepend them with "--"\n
    """
    user, password, host = parse_connection_string(connection_string)

    if rpass:
        password = getpass.getpass('Password: '******'Passphrase: ') if rphrase else None

    executor = SSHExecutor(
        host,
        port=port,
        user=user,
        password=password,
        key_path=identity,
        passphrase=passphrase,
    )

    with executor:
        res = json_repr(*executor.execute(command, command_args))

    click.echo(res)
예제 #2
0
 def test_ok(self):
     self.executor = SSHExecutor('127.0.0.1',
                                 user='******',
                                 password='******')
     with self.executor:
         transport = self.executor.client.get_transport()
         self.assertTrue(transport.is_active())
예제 #3
0
 def setUp(self):
     self.executor = SSHExecutor('127.0.0.1',
                                 user='******',
                                 password='******')
예제 #4
0
 def test_empty_user(self):
     self.executor = SSHExecutor('127.0.0.1',
                                 user='',
                                 password='******')
     with self.assertRaises(ValueError):
         self.executor.connect()
예제 #5
0
 def test_empty_password(self):
     self.executor = SSHExecutor('127.0.0.1', user='******', password='')
     with self.assertRaises(ValueError):
         self.executor.connect()
예제 #6
0
 def test_wrong_account(self):
     self.executor = SSHExecutor('127.0.0.1',
                                 user='******',
                                 password='******')
     with self.assertRaises(ValueError):
         self.executor.connect()
예제 #7
0
 def test_connection_to_non_existent_domain(self):
     self.executor = SSHExecutor('nonexistentdomain.ua',
                                 user='******',
                                 password='******')
     with self.assertRaises(ValueError):
         self.executor.connect()