question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to pass a list of show commands

See original GitHub issue

There 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:

  1. 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.
  2. 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:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Feb 13, 2020

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 of send_command besides expect_string (i.e. this would have to come from expect_list).

Return a dictionary of results:

key —> the command set value —> the send_command response corresponding to that key.

1reaction
daanvdsandencommented, Jan 8, 2020

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.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found