cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
697
Views
4
Helpful
3
Replies

pyATS: custom fields when building testbed from CSV

grahamt-sec
Level 1
Level 1

I want to add a custom field of information to my testbed. I am using --add-keys. The file processes fine but validation fails:

YAML Lint Messages
------------------

Errors
------
- ['devices', 'WANRTR01']: Unsupported keys:
"wan_intf" (my_testbed.yaml line:16 column:5)

My csv looks like this:

hostname,ip,username,password,protocol,os,enable_password,platform,wan_intf
WANRTR01,192.168.4.5,user1,xx,ssh,iosxe,xx,C8300-2N2S-4T2X,Te0/0/4

This does create a dict, but it looks to be in the wrong place. (? should be under custom:)
devices:
ATRTEWPIP1:
connections:
cli:
ip: 192.168.4.5
protocol: ssh
credentials:
default:
password: '%ENC{==}'
username: user1
enable:
password: '%ENC{==}'
os: iosxe
platform: C8300-2N2S-4T2X
type: iosxe
wan_intf: Te0/0/4

I also used 'custom' as the column header but that did not work either. The lint came back with expecting dict got string on a couple tries.

How do I add custom fields/data to the CSV file in order to result with at valid testbed.yaml?

3 Replies 3

Marcel Zehnder
Spotlight
Spotlight

Hi 
According to the pyats create doc all unknow key/values will be added to the root of the device (so the behaviour works as designed).

Your best option is using a Jinja template with python. Have a look at https://github.com/maercu/ciscosupportexamples/tree/main/pyatstb as a starting point.

HTH

Hey @grahamt-sec  i think you need to add a new column to the CSV file with the header 'custom' The value of this column should be a dictionary of custom fields and values.

hostname,ip,username,password,protocol,os,enable_password,platform,wan_intf,custom
WANRTR01,192.168.4.5,user1,xx,ssh,iosxe,xx,C8300-2N2S-4T2X,Te0/0/4,{'wan_intf': 'Te0/0/4'}

It should create something like this

devices:
  WANRTR01:
    connections:
      cli:
        ip: 192.168.4.5
        protocol: ssh
        credentials:
          default:
            password: '%ENC{==}'
            username: user1
        enable:
          password: '%ENC{==}'
        os: iosxe
        platform: C8300-2N2S-4T2X
        type: iosxe
    custom:
      wan_intf: Te0/0/4

If you then use the '--add-keys' option into the add the custom field to the testbed you should have the new testbed.yaml file with the custom field added 

pyats create testbed file --path my_devices.csv --output yaml/my_testbed.yaml --add-keys custom

 

devices:
  WANRTR01:
    connections:
      cli:
        ip: 192.168.4.5
        protocol: ssh
        credentials:
          default:
            password: '%ENC{==}'
            username: user1
        enable:
          password: '%ENC{==}'
        os: iosxe
        platform: C8300-2N2S-4T2X
        type: iosxe
    custom:
      wan_intf: Te0/0/4

Here is a link https://pubhub.devnetcloud.com/media/pyats-getting-started/docs/quickstart/manageconnections.html and this too https://pubhub.devnetcloud.com/media/pyats/docs/tcl/datastructures.html?highlight=custom

Try this and see if its what you are looking for.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Ruben Cocheno
Spotlight
Spotlight

@grahamt-sec 

All sorted?

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/