napalm-automation / napalm-junos

Apache License 2.0
22 stars 42 forks source link

Junos cli: raw command cause rpc warning #183

Closed sincerywaing closed 7 years ago

sincerywaing commented 7 years ago

Description of Issue/Question

if we want to use dev.cli(cmd) and get the output, it seems: 1) for some command it won't execute as expected, like ping or trace 2) for some command we get warning which mess up the output

To provide user more flexibility, I want to provide a way for user to enter show/ping/trace command he/she want to use in an interaction way.

anyway we can tweak this?

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

[* ] Yes [ ] No

Setup

run any command has certain output

napalm-junos version

(Paste verbatim output from pip freeze | grep napalm-junos between quotes below)

0.11.0

JunOS version

(Paste verbatim output from show version and haiku between quotes below)

any

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:612: RuntimeWarning: 
CLI command is for debug use only!
Instead of:
cli('show bgp summary')
Use:
rpc.get_bgp_summary_information()

  warnings.warn(warning_string, RuntimeWarning)

/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:612: RuntimeWarning: 
CLI command is for debug use only!
Instead of:
cli('show ver')
Use:
rpc.get_software_information()

  warnings.warn(warning_string, RuntimeWarning)
mirceaulinic commented 7 years ago

Hi @sincerywaing:

for some command it won't execute as expected, like ping or trace

Unfortunately, there's nothing we can do about that -- some commands are forbidden from CLI execution. This is intentional: naturally and understandably, Juniper wants to discourage users from doing this. I would suggest you write a private method in your environment that does what you need. Just out of curiosity: is there any information you'd need from cli('show bgp summary') that's not provided by the existing get_bgp_neighbors or get_bgp_neighbors_detail?

for some command we get warning which mess up the output

Apparently, there's a way to prevent this: https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/device.py#L606 the cli method has a flag called warning which can be turned off when executing. I believe we can just turn it off by default, as the other platforms don't throw any warning when executing raw CLI commands. Eventually we can have another optional flag (defaulting to False) to raise this warning when executing CLI commands, but I see no gain by doing this. Any thoughts on this @dbarrosop?

sincerywaing commented 7 years ago

@mirceaulinic make much sense. I'm just exploring a way to let user run some show command after they merge the config so they can do some check. Do you want me to file a pr to turn it off? I think again feel that optional_arg cli_warning might not needed. I'd file a pr to turn it off. Let me know if you agree so.

mirceaulinic commented 7 years ago

Solved in #186