Get connection forwarding to work

os-repl
root 2022-11-28 19:25:39 +00:00
parent 9ae51586c8
commit a012173564
1 changed files with 14 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import uuid
import lxd_interface import lxd_interface
import threading import threading
import logging import logging
import select
import time import time
import inspect import inspect
@ -12,7 +13,7 @@ logger = logging.getLogger(__name__)
def check_channel_shell_request(self, channel): def check_channel_shell_request(self, channel):
logger.debug(channel) logger.debug("Check channel shell request: %s" % channel.get_id())
Runner(self, channel).start() Runner(self, channel).start()
return True return True
@ -53,18 +54,21 @@ class Runner(threading.Thread):
ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy) ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy)
ssh_client.connect(vm_ip, username='root', password=self.instance_password) ssh_client.connect(vm_ip, username='root', password=self.instance_password)
self.transport = ssh_client.get_transport() self.transport = ssh_client.get_transport()
tmp_channel = ssh_client.invoke_shell() client_channel = ssh_client.invoke_shell()
self.channel.other_channel = tmp_channel
self.channel.__getattribute__ = Patch.__getattribute__
while True: while True:
time.sleep(1000) r, w, e = select.select([client_channel, self.channel], [], [])
if self.channel in r:
x = self.channel.recv(1024)
if len(x) == 0:
break
client_channel.send(x)
if client_channel in r:
class Patch: x = client_channel.recv(1024)
def __getattribute__(self, item): if len(x) == 0:
getattr(self.other_channel, item) break
self.channel.send(x)
Handler.check_channel_shell_request = check_channel_shell_request Handler.check_channel_shell_request = check_channel_shell_request