09-21-2023 09:31 AM
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?
09-22-2023 12:41 AM
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
09-22-2023 12:42 AM
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.
02-02-2024 12:29 PM
All sorted?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide