diff --git a/lib/netconify/cmdo.py b/lib/netconify/cmdo.py index d0e57d9..8626bf8 100644 --- a/lib/netconify/cmdo.py +++ b/lib/netconify/cmdo.py @@ -317,6 +317,7 @@ def _tty_login(self): host, port = re.split('[,:]', self._args.telnet) tty_args['host'] = host tty_args['port'] = port + tty_args['baud'] = self._args.baud self.console = ('telnet', host, port) self._tty = netconify.Telnet(**tty_args) elif self._args.ssh is not None: diff --git a/lib/netconify/tty_telnet.py b/lib/netconify/tty_telnet.py index f86f1a5..1ab06a4 100644 --- a/lib/netconify/tty_telnet.py +++ b/lib/netconify/tty_telnet.py @@ -31,6 +31,7 @@ def __init__(self, host, port, **kvargs): self.host = host self.port = port self.timeout = kvargs.get('timeout', self.TIMEOUT) + self.baud = kvargs.get('baud', 9600) self._tty_name = "{0}:{1}".format(host, port) Terminal.__init__(self, **kvargs) @@ -62,12 +63,34 @@ def _tty_close(self): # ------------------------------------------------------------------------- def write(self, content): - """ write content + """ - self._tn.write(content + '\n') + # If baud set to 0 write full speed + if (int(self.baud) == 0): + self._tn.write(content + '\n') + return None + + # Write data according to defined baud + # per 8 bit of data there are 2 additional bits on the line + # (parity and stop bits) + for char in content: + self._tn.write(char) + wtime = 10/float(self.baud) + sleep(wtime) # do not remove + self._tn.write('\n') def rawwrite(self, content): - """ write content as-is """ - self._tn.write(content) + # If baud set to 0 write full speed + if (int(self.baud) == 0): + self._tn.write(content + '\n') + return None + + # Write data according to defined baud + # per 1 byte of data there are 2 additional bits on the line + # (parity and stop bits) + for char in content: + self._tn.write(char) + wtime = 10/float(self.baud) + sleep(wtime) # do not remove + self._tn.write('\n’) def read(self): """ read a single line """