cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
723
Views
0
Helpful
4
Replies

pyATS Learning "config" feature

toeknee2120
Community Member

I noticed that when you do a

device.learn("all") or device.learn("config"), the config dictionary seems to be built strangely. It seems if a value has over 80 characters, its string is carried over to the next key. My guess is it has something to do with terminal width, but it's a little annoying. Has anyone noticed this, or is there a way around it?

{
"some setting": "...some long value ov"
"er 80 characters": {}
}
4 Replies 4

balaji.bandi
Hall of Fame
Hall of Fame

never tried all - may be when i get access to Lab will try.

But I used the code below get information it works. what is the use case of get all information.

device.learn("interface")
device.learn("routing")

Alternatively you can try below :

device.execute("terminal length 0")
cfg = device.execute("show running-config")

BB

=====️ Preenayamo Vasudevam ️=====

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

what is the use case of get all information.

One reason to learn all would be to create a mock device.

But I used the code below get information it works. 

device.learn("interface")
device.learn("routing")

Yes, device.learn("all") and device.learn("config") both work and get the information, it's just weird how the data is parsed.
I did notice if you do the following, it seems to parse fine.

device.execute("terminal length 0")
device.execute("terminal width 200")
config = device.learn("config") # or config = device.learn("all").config 
print(config)

 

Alternatively you can try below :

device.execute("terminal length 0")
cfg = device.execute("show running-config")


Thanks. I was just trying to use .learn() instead of executing the command myself because of what the docs mention:

 

Why use learn instead of a parser? The parsed output for different devices can result in different data structures. The learn function, by contrast, results in a consistent set of keys, which means that you can write one script that works on different devices.

ok, on what device are you trying? Nexus or IOS XE?

Let me test when I get a chance on my Lab,

BB

=====️ Preenayamo Vasudevam ️=====

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

NXOS