Add ability to pass a list of show commands
See original GitHub issueThere are frequently questions asked in online forums of how best to send a list of separate show
type commands to a device with Netmiko. Today there are two methods:
- Utilize
send_config_set()
, which is less than ideal, because of two reasons. First, it requires the user to have write access to the device, and second it will attempt to issue the commands in the configuration mode which potentially will not function depending on the network device vendor/platform. - Utilize a looping construct in Python to iterate over the list of commands and issue individual
send_command()
and return the output. While this is commonly used, having every user of Netmiko re-invent the wheel is less than optimal.
Ideally, there would be another method such as send_command_list()
, that accepted a sequence of Str and issued the commands itself. It would then return a Dict with the command string as the key, and the output of those commands in strings as the value.
I have implemented something similar to this here: https://github.com/lykinsbd/naas/blob/master/naas/library/netmiko_lib.py#L24
While not directly applicable for upstreaming, the general idea is there and can form the basis of a send_command_list()
method. I can look at creating a PR for this later this week.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Pass list as command line argument in Python
For a program to be able to use it, it has to be imported from the “sys” module. The arguments so obtained are...
Read more >Show Commands
This command lists the files that were used to bring up the system, the files to use the next time the system reboots,...
Read more >How to pass an entire list as command line argument in ...
You can use action=append to allow repeated arguments to be collected into a single list. >>> parser = argparse.ArgumentParser() >>> parser.
Read more >Adding arguments and options to your Bash scripts
In this article, you've used positional parameters to enter data into the Bash program during invocation from the command line and used options ......
Read more >Python Command Line Arguments
Adding the capability of processing Python command line arguments provides a user-friendly interface to your text-based command line program.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am warming a bit to the idea of building a method
send_command_list
Take
expect_list
as an argument. Support all of the other arguments ofsend_command
besidesexpect_string
(i.e. this would have to come fromexpect_list
).Return a dictionary of results:
key —> the command set value —> the send_command response corresponding to that key.
It would be great if the dict values are the result of the send_command function. So the TextFSM integration is still there. And these parameters are passable to the function.