08-12-2021 08:06 AM
Hi,
I'm trying to automate the configuration of remote Cisco devices using pyATS. Going thru the online documentation I found the following script excerpt:
# establish basic connectivity ios_1.connect() # issue commands print(ios_1.execute('show version')) ios_1.configure(''' interface GigabitEthernet0/0 ip address 10.10.10.1 255.255.255.0 ''')
This is pretty much what I was looking for. I tested and worked just fine. However, I'd like to use variables instead of fixed values, like : ip address <IP_Address> <Mask> or something like that.
By this way I could create a script that takes arguments and the argument could be the ip addres and the mask. Given that those are IOS commands I couldn't figure out how to make it work. I'd appreciate any clue on this or, maybe you can suggest a different approach.
Thanks!
08-13-2021 12:30 AM
@oslopez you could import ipaddress http://docs.python.org/3/library/ipaddress and use the input function.
Hope this helps.
12-05-2023 06:38 AM
This is what templating is for.
If you have simple needs, maybe this is probably overkill, but Jinja2 templates would be the way to go for more complex/complete templating. https://svn.python.org/projects/external/Jinja-2.1.1/docs/_build/html/index.html
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