def shell(self):
"""Open a shell."""
# Make sure we can restore the terminal to a working state after
# interactive stuff is over
oldtty = None
try:
oldtty = termios.tcgetattr(self.input.fileno())
# Set tty mode to raw - this is a bit dangerous because it stops
# Ctrl+C working! But that is required so that you can Ctrl+C
# remote things
tty.setraw(self.input.fileno())
# For testing you could use cbreak mode - here Ctrl+C will kill the
# local yaybu instance but otherwise is quite like raw mode
# tty.setcbreak(self.input.fileno())
# We want non-blocking mode, otherwise session might hang
# This might cause socket.timeout exceptions, which we just ignore
# for read() operations
self.channel.settimeout(0.0)
self.handle_communications()
except Exception, e:
LOG.warn(e, exc_info=True)
finally:
if oldtty:
termios.tcsetattr(self.input.fileno(), termios.TCSADRAIN, oldtty)
self.channel.close()
评论列表
文章目录