def login(self, switch):
""" login
logs into specified switch """
# set up ssh client
ssh_setup = paramiko.SSHClient()
# add missing host key policy (set as auto)
ssh_setup.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# connect to switch
ssh_setup.connect(
switch,
username=self.user,
password=self.user_pw,
look_for_keys=False,
allow_agent=False,
)
# set up transport channel for session
transport = ssh_setup.get_transport()
# invoke session
self.ssh_session = transport.open_session()
# set up for interactive mode, multiple commands - pty
self.ssh_session.get_pty()
# invoke session's shell
self.ssh_session.invoke_shell()
# keep session active with parameters while class is initialized
self.ssh_session.keep_this = ssh_setup
评论列表
文章目录