def shell(self, cmd: str): if self.accessible == False: print("No access info...") return False pkey_file = self.pkey.open() client = SSHClient() client.set_missing_host_key_policy(AutoAddPolicy()) client.connect(hostname=self.host, pkey=Ed25519Key.from_private_key( pkey_file, self.passphrase), passphrase=self.passphrase, username=self.user) _, _, stderr = client.exec_command(cmd) for line in stderr: print(line, file=sys.stderr) client.close()
def ping(self): if self.accessible == False: print("No access info...") return False pkey_file = self.pkey.open() client = SSHClient() client.set_missing_host_key_policy(AutoAddPolicy()) try: client.connect(hostname=self.host, pkey=Ed25519Key.from_private_key( pkey_file, self.passphrase), passphrase=self.passphrase, username=self.user) print(f"{self.name} is started.", flush=True) client.close() return True except NoValidConnectionsError as e: print(e, flush=True) return False
def _get_server(self, platform_ssh: bool): """Method for getting and starting ssh server.""" if platform_ssh: return None try: pkey = RSAKey.from_private_key( StringIO(self.tunnel["privateKey"]), password=self.tunnel.get("password")) except SSHException: pkey = Ed25519Key.from_private_key( StringIO(self.tunnel["privateKey"]), password=self.tunnel.get("password")) server = SSHTunnelForwarder(ssh_address_or_host=(self.tunnel["host"], self.tunnel["port"]), ssh_username=self.tunnel["username"], ssh_password=self.tunnel.get("password"), ssh_pkey=pkey, remote_bind_address=(self.host, self.port)) server.start() return server
def test_ed25519_load_from_file_obj(self): with open(_support("test_ed25519.key")) as pkey_fileobj: key = Ed25519Key.from_private_key(pkey_fileobj) self.assertEqual(key, key) self.assertTrue(key.can_sign())
def test_ed25519_load_from_file_obj(self): with open(test_path('test_ed25519.key')) as pkey_fileobj: key = Ed25519Key.from_private_key(pkey_fileobj) self.assertEqual(key, key) self.assertTrue(key.can_sign())