cisco-ie / cisco-gnmi-python

CLI and library wrapping gNMI functionality to ease usage with Cisco implementations in Python programs.
https://pypi.org/project/cisco-gnmi/
Apache License 2.0
41 stars 18 forks source link

Suggest examples in the README (or Wiki). #40

Closed mike-albano closed 4 years ago

mike-albano commented 4 years ago

I could use an example of how to formulate a Subscription.

Suggestion for documentation: For the README or WiKi, I'd suggest something like the following:

Working example of OpenConfig Streaming Telemetry on Aceess Point.

from cisco_gnmi import ClientBuilder

builder = ClientBuilder('192.168.0.5:8080') builder.set_secure_from_target() builder.set_ssl_target_override('openconfig.mojonetworks.com') builder.set_call_authentication('admin', 'admin') client = builder.construct()

paths = [client.parse_xpath_to_gnmi_path('/access-points/access-point[hostname="test-ap.example.net"]/radios/radio[id="0"]/state/rx-noise-channel-utilization/')] print(client.get(paths))

You may also want to provide a pointer in your documentation that list-key values must be quoted due to your xpath parsing. Even if the list-key is an int (like the radio id in the above example).

remingtonc commented 4 years ago

Good idea - certainly something to do. The XPath predicates needing to be strings seems more like a bug to be investigated, filing.

mike-albano commented 4 years ago

Sg, thanks. If you could share a sample of valid syntax for a subscribe (which passes the 'validate_request') I'd be happy to do some testing with net elements we have which support ST as of now.

remingtonc commented 4 years ago

@mike-albano I'll be away from a laptop until Monday but in the meantime check out the subscribe_xpaths method in the respective OS clients. Will help debug, but not as effectively for several days!

remingtonc commented 4 years ago

Addressing in doc-examples.

remingtonc commented 4 years ago

@mike-albano Apologies for the delay here. In the meantime, added some level of a CLI which lightly demonstrates usage of the library. https://github.com/cisco-ie/cisco-gnmi-python/blob/doc-examples/src/cisco_gnmi/cli.py#L148

Reading your issue more, I see this doesn't totally address what you are asking. Will address this tonight with some more direct examples.

mike-albano commented 4 years ago

Sounds good. I've been messing with it a bit; still a little unclear on your args.os, so I've been manually over-riding, but I'll wait for some examples then take a closer look. Thanks.

remingtonc commented 4 years ago

@mike-albano The args.os corresponds to the OS-specific wrapper to utilize. https://github.com/cisco-ie/cisco-gnmi-python/blob/master/src/cisco_gnmi/builder.py#L77-L82

So specifying IOS XR will give IOS XR convenience functions, IOS XE for IOS XE, etc. None simply returns the base Client implementation.

remingtonc commented 4 years ago

@mike-albano It's not pretty but I'm lagging on this too hard to not give some examples - here is a "custom" usage of the base Client class. Several other scripts in branch directory. https://github.com/cisco-ie/cisco-gnmi-python/blob/actual-doc-examples/examples/custom.py

Please ask any questions, happy to collaborate directly on code if desired. Can set something up meeting-wise.