Posted on July 3, 2019 11:24 am
 |  Asked by Davide Ganna
 |  124 views
RESOLVED
0
0
Print Friendly, PDF & Email

Since I have problems posting the question, the Arista Support suggested me to attach the message as a.jpg file.
Please refer to the image, my post is written there.

Attachments:
2
Posted by Tamas Plugor
Answered on July 3, 2019 11:35 am

Hi Davide,

One of the reasons would be that you’re not taking care of timeouts.

I’ve written this script which should work (attached telnet2.txt)

When you run it, it’ll ask you for the switch IP, username and password

You should see something like this:

python telnet2.py
Enter switch IP: 10.83.13.139
Username: cvpadmin
Password:

Last login: Wed Jul 3 11:22:18 from 10.83.36.204

ats324...11:29:40#terminal length 0
Pagination disabled.
ats324...11:29:41#
ats324...11:29:42#configure
ats324...11:29:42(config)#interface Ethernet2
ats324...11:29:43(config-if-Et2)#description TELNET-test
ats324...11:29:44(config-if-Et2)#no switchport
ats324...11:29:45(config-if-Et2)#ip address 192.168.133.25/24
ats324...11:29:46(config-if-Et2)#

Ultimately it'd be better to use eAPI, much faster and simpler then using telnet The following guide should be helpful: https://eos.arista.com/arista-eapi-101/

Hope it helps! Thanks,
Tamas

Attachments:

Awesome. It works perfectly.

I changed line 28: switch_output instead of siwtch_output (simple typing error, I write this for others)
And I replaced line 39 with connection.write(“enable n”) because I got some errors cause we need to enter enable mode. What does “connection.write(“terminal length 0n”)” mean?

As you wrote before: “One of the reasons would be that you’re not taking care of timeouts.”
Shouldn’t be the timeout disabled if I don’t set that?

Thank you very much :)

(Davide Ganna at July 4, 2019 7:56 am)

Also, I saw that adding a delay is extremely important. I tried without that and it doesn’t work. Why do we have to add this delay? If I want to configure 20 VLANs and give each one a name (VLAN_1, VLAN_2 etc) it requires 40 seconds only for that. Imagine a script with far more commands…isn’t there a better option?

(Davide Ganna at July 4, 2019 9:34 am)

Sorry for the typo, I must’ve copy pasted the script before I corrected it. As the comment says terlminal lenghth 0 disables pagination, so when you run show commands that have longer outputs, it disables the –More– prompt

There is a better option, as I mentioned, we highly recommend using eAPI, it will take under 1 second to configure 100 vlans.
Telnetlib is very slow and unoptimized, you can play with the timeouts, like lower them, but based on my tests you cannot go sub-second, this is true for connecting to linux VMs as well.

You can either use eAPI with jsonrpclib (a good starter would be: https://eos.arista.com/arista-eapi-101/) or you can use a wrapper like pyeapi:

https://pyeapi.readthedocs.io/en/latest/index.html#intro

or goeapi or ruby eapi
https://github.com/arista-eosplus?utf8=%E2%9C%93&q=eapi&type=&language=

Using an SSH lib like netmiko would be also much faster than telnetlib and it’s compatible with most of the vendors.

Ansible would also be a good option, which can use either SSH or eAPI to connect to EOS/vEOS/cEOS.

(Tamas Plugor at July 4, 2019 3:12 pm)

Perfect, thank you.

Davide

(Davide Ganna at July 5, 2019 7:08 am)

Post your Answer

You must be logged in to post an answer.