Reputation: 997
I'm using the Netmiko library to connect to devices and send new config commands via the "send_config_set" method. Currently, I am doing this on Cisco IOS devices only. But I am making something that will allow a user to enter any commands (with some exceptions) and so I am trying to understand how to interpret the output I get.
As I understand, Netmiko currently only returns the raw output. But what would be useful for me is to determine if something went wrong during the execution of those commands - maybe like a boolean flag?
For example, lets say I do this:
send_config_set(['abcd'])
The response I would get is:
config term
Enter configuration commands, one per line. End with CNTL/Z.
switch(config)#abcd
^
% Invalid input detected at '^' marker.
switch(config)#end
switch#
Clearly, in this case there was an error since the command was invalid. But Netmiko has no way to tell me that, it just gives the output and I guess wants me to decide.
I'm not a network engineer so I don't really know what the possible error outputs could be (i.e. what to look for in the response), I also don't know all the commands the user will try so can't account for everything.
What I did notice is when Cisco IOS appears to have some errors, they always seem to be starting with a % Invalid
or % Access
or something like that beginning with a % - so I wonder if that is enough for me to search the output for those and then set a flag myself to show an error was encountered? Maybe I can build a list of strings to look for in the output?
Although, I'm not convinced this is all that reliable and am keen to hear others opinions on the best way to do this.
Upvotes: 1
Views: 2228
Reputation: 285
Netmiko is a "screen-scraping" library; it scrapes text off the screen and sends them to you.
What you are describing is exactly the reason why API interfaces (like NETCONF) are superior to screen-scraping interfaces.
It is true that the Cisco IOS messages that appear when you apply a configuration command are preceded by %, but not all of them are errors. For example:
Switch(config-if)#spanning-tree portfast
%Warning: portfast should only be enabled on ports connected to a single host.
Connecting hubs, concentrators, switches, bridges, etc.to this interface
when portfast is enabled, can cause temporary spanning tree loops.
Use with CAUTION
This is the reason why Netmiko simply passes on the message to the user, so that they can take action based on the message. Since you also appear to be building some sort of wrapper around Netmiko, perhaps you should do the same.
Upvotes: 2