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)
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())
def setUp(self): self.executor = SSHExecutor('127.0.0.1', user='******', password='******')
def test_empty_user(self): self.executor = SSHExecutor('127.0.0.1', user='', password='******') with self.assertRaises(ValueError): self.executor.connect()
def test_empty_password(self): self.executor = SSHExecutor('127.0.0.1', user='******', password='') with self.assertRaises(ValueError): self.executor.connect()
def test_wrong_account(self): self.executor = SSHExecutor('127.0.0.1', user='******', password='******') with self.assertRaises(ValueError): self.executor.connect()
def test_connection_to_non_existent_domain(self): self.executor = SSHExecutor('nonexistentdomain.ua', user='******', password='******') with self.assertRaises(ValueError): self.executor.connect()