def ssh_execute_cli(cli, sff_locator):
""" """
remoteConnectionSetup = paramiko.SSHClient()
remoteConnectionSetup.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remoteConnectionSetup.connect(sff_locator,
username='cisco', password='cisco',
allow_agent=False, look_for_keys=False)
# invoke the shell so can send multiple commands
sshChannel = remoteConnectionSetup.invoke_shell()
# make sure in enable mode so we can configure the router
is_enabled = sshChannel.recv(1000)
if "#" not in is_enabled:
enable_router(sshChannel)
# execute the necessary commands to configure the router
send_command_and_wait_for_execution(sshChannel, "conf t\n", "#", False)
send_command_and_wait_for_execution(sshChannel, cli + '\n', "#", False)
remoteConnectionSetup.close() # close the connection
评论列表
文章目录