question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to connect to Cisco IOS-XR

See original GitHub issue

Hi Ron,

Greetings. I am working with multiple vendor networking devices to execute commands. With the below asyncssh code, I verified connecting to Nokia, Huawei and a few models of Cisco. For some reason, I am unable to connect to Cisco ASR9K which is a IOS-XR device. It returns asyncssh.misc.ConnectionLost: Connection lost error every time.

async with asyncssh.connect(host, username=user, password=pwd, port=22,
                                known_hosts=None, kex_algs=k_algs, encryption_algs=e_algs, mac_algs=m_algs,
                                compression_algs=None, login_timeout=60, ) as conn:
        async with conn.create_process() as process:
            print('after conn')
            print("**************************%s******************************" % disable_paging_cmd)
            process.stdin.write(f'{disable_paging_cmd}\r\n')
            print("**************************%s******************************" % cmd)
            process.stdin.write(f'{cmd}\r\n')
            print("**************************%s******************************" % exit_command)
            process.stdin.write(f'{exit_command}\r\n')
            line = await process.stdout.read()
            print(str(line))

Any special cases to be handled for IOS-XR?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ronfcommented, Jan 20, 2022

Sorry - the ValueError was my mistake. It should have been '+ssh-dss', rather than '+ssh_dss', but it looks like you figured that out.

Regarding the output hang, see if sending only ‘\r’ as the line ending works rather than ‘\r\n’. If you set a terminal type, the remote system would be expecting your terminal to only send carriage return when you hit “enter” after typing a command. Also, is the “quit” command you are sending normally enough to trigger the server to do a connection close? If not, that could explain the hang. I’m not seeing any sign of it trying to close the connection in your debug output.

1reaction
mon-216commented, Jan 20, 2022

Hi Ron, thanks for your timely responses. After setting the host_key_algs, I had to set the term_type too. I am able to connect to IOS-XR (ASR9K) box with asyncssh now. Pasting below the options I added for someone’s reference

server_host_key_algs=['ssh-dss'], term_type='xterm-color', term_size=(80, 24)

However the issue with NCS540 (another IOS-XR) device still exists. I have the term_type set as you suggested. The Session request failed error is gone. But after opening the session, the commands are executed and the session hangs without reading any output indefinitely.

Debug logs -

DEBUG:asyncssh:[conn=0, chan=0] Set write buffer limits: low-water=16384, high-water=65536
INFO:asyncssh:[conn=0, chan=0] Requesting new SSH session
DEBUG:asyncssh:[conn=0, chan=0]   Initial recv window 2097152, packet size 32768
DEBUG:asyncssh:[conn=0, chan=0]   Initial send window 2097152, packet size 32768
DEBUG:asyncssh:[conn=0, chan=0]   Terminal type: xterm-color
DEBUG:asyncssh:[conn=0, chan=0]   Terminal size: 80x24
INFO:asyncssh:[conn=0, chan=0]   Interactive shell requested
after conn
**************************terminal length 0******************************
DEBUG:asyncssh:[conn=0, chan=0] Sending 19 data bytes
**************************show bgp neighbor******************************
DEBUG:asyncssh:[conn=0, chan=0] Sending 19 data bytes
**************************quit******************************
DEBUG:asyncssh:[conn=0, chan=0] Sending 6 data bytes
DEBUG:asyncssh:[conn=0, chan=0] Reading from channel started
DEBUG:asyncssh:[conn=0, chan=0] Received 21 data bytes
DEBUG:asyncssh:[conn=0, chan=0] Received 21 data bytes
DEBUG:asyncssh:[conn=0, chan=0] Received 8 data bytes
DEBUG:asyncssh:[conn=0, chan=0] Received 147 data bytes
DEBUG:asyncssh:[conn=0, chan=0] Received 4 data bytes
DEBUG:asyncssh:[conn=0, chan=0] Received 35 data bytes
^C

I tried changing the term_type to vt100 after checking some config docs of NCS540. But that doesn’t work either

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: IOS XR failed to boot - Cisco Community
- Connect to RP console. - Enter rommon by hitting Ctrl+c until you get the rommon prompt. - Enter these commands to disable...
Read more >
Solved: Login Problem at IOS-XR(ASR9010) - Cisco Community
Solved: The IOS device has a command of login block-for 60 ... i want do it in the IOS-XR device i can't find...
Read more >
Solved: Unable to connect to IOS-XR 6.5.2 with Paramiko.
Hi! After upgrade to IOS-XR 6.5.2 none of my automations are able to connect to to the router. Both my ncclient and Netmiko...
Read more >
Can't connect (ssh) to devbox / IOS XRV 9000
Can anyone help me on this since its blocking me since yesterday ? I'm running into same issue even after spinning up a...
Read more >
SSH fail access on IOS XR, ASR9000 - Cisco Community
Hi actually we have a trouble with the operation with SSH an access to ASR9000, we installed and actived the PX.PIE packet for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found