from time import sleep import logging from jnpr.junos import exception as EzErrors from jnpr.junos.transport.tty_netconf import tty_netconf logger = logging.getLogger("jnpr.junos.tty") __all__ = ["Terminal"] # ========================================================================= # Terminal class # ========================================================================= class Terminal(object): """ Terminal is used to bootstrap Junos New Out of the Box (NOOB) device over the CONSOLE port. The general use-case is to setup the minimal configuration so that the device is IP reachable using SSH and NETCONF for remote management. Serial is needed for Junos devices that do not support the DHCP 'auto-installation' or 'ZTP' feature; i.e. you *MUST* do the NOOB configuration via the CONSOLE. Serial is also useful for situations even when the Junos device supports auto-DHCP, but is not an option due to the specific situation """ TIMEOUT = 0.2 # serial readline timeout, seconds EXPECT_TIMEOUT = 10 # total read timeout, seconds LOGIN_RETRY = 20 # total number of passes thru login state-machine _ST_INIT = 0 _ST_LOADER = 1 _ST_LOGIN = 2 _ST_PASSWD = 3 _ST_DONE = 4 _ST_BAD_PASSWD = 5 _ST_TTY_NOLOGIN = 6 _ST_TTY_OPTION = 7 _ST_TTY_HOTKEY = 8 _re_pat_login = r"(?Pogin:\s*$)" _RE_PAT = [ r"(?Poader>\s*$)", _re_pat_login, r"(?Password:\s*$)", "(?Pogin incorrect)", r"(?P\s*)", r"(?P%|#|(~\$)\s*$)", r'(?P[^\-"]>\s*$)', r"(?P