cisco-ie / ios-xr-grpc-python

IOS-XR gRPC Python connectivity library.
Other
15 stars 14 forks source link

How to use other .yang moduels? #29

Open davehouser1 opened 3 years ago

davehouser1 commented 3 years ago

Hi, First of all, understand I am learning gRPC to use with our CiscoXR. Therefore if anything I ask seems amateurish, that is why. I read though the wiki and Readme. It looks like this repo has two .json files which you use as the structure for sending GRPC commands to adjust BGP. How does one use other yang modules? Looking at the yang/cisco repo, there are a variety of modules to use. Would like to use one based on my version (7.2.1). I tried converting the same .yang module you used to xml then from xml to json, but the structure looks completely different. How did you create / convert your .json files?

brmcdoug commented 3 years ago

Hi Dave, I've stashed a number of sample json objects for working with other yang models here:

https://github.com/cisco-ie/ios-xr-grpc-python/tree/brmcdoug/examples/json

We use pyang to walk the structure of a given data model, then manually create json objects by following the output of pyang.

https://pypi.org/project/pyang/

A couple pyang examples: pyang -f tree --tree-depth 4 Cisco-IOS-XR-ipv4-bgp-oper.yang pyang -f tree --tree-depth 5 openconfig-lldp.yang | more HTH -Bruce

davehouser1 commented 3 years ago

@brmcdoug,

Ah! I didn't think to look in a different branch. Now I know they are under your branch "brmcdoug".

I am familiar with pyang, also familiar with those commands. To confirm, there is no automated way of working with the yang files. The Yang files only define the structure of the data. It is up to the developer to create parts of that structure that want to point point with a different data format (json seems to be the only format supported with your scripts?). That's fairly impressive that so many of these json files were manually created.

Unrelated, I can't find the ems.pem file anywhere on my cisco box. I checked in /misc/config/grpc/ (No grpc/ dir) or /var/xr/config/grpc (No xr/ dir). Any idea how to generate a ems.pem file or where it would be hiding (Running 7.2.1)?

I appreciate your quick response and patience with my simple questions :)

brmcdoug commented 3 years ago

Haha, yeah, those were manually created...caffeine and lots of ctrl-c-ctrl-v. I haven't tried it myself, but this might offer a way to do so in an automated fashion: https://stackoverflow.com/questions/30503356/how-to-convert-yang-data-model-to-json-data

As for ems.pem, make sure to configure grpc on the box itself with TLS enabled (this is the default setting).

RP/0/RP0/CPU0:IE-5508-2#sho run grpc Thu Jul 1 21:02:19.847 PDT grpc port 57400 address-family ipv4 service-layer

RP/0/RP0/CPU0:IE-5508-2#run Thu Jul 1 21:01:50.959 PDT [xr-vm_node0_RP0_CPU0:~]$cd /misc/config/grpc/ [xr-vm_node0_RP0_CPU0:/misc/config/grpc]$ls ca.cert ca.cert.bkpb dialout ems.key ems.key.backup ems.key.bkpb ems.pem ems.pem.backup ems.pem.bkpb [xr-vm_node0_RP0_CPU0:/misc/config/grpc]$exit

davehouser1 commented 3 years ago

@brmcdoug, thanks that worked, tls / ems.pem available now. I am still confused on the process of using other cisco native yang files. I have Cisco XR 7.2.1 yang files. I grasp that I need to build some structure in json from those files. Manually seems to be the way to do it with pyang to guide illustrating the structure. And I get that I can use the grpc python module to run the actual client interaction with the host. Aside from that, I still have so many knowledge gaps in-between. I don't think the json structure you created (based of v6 yangs?) works with 7.2.1 hence why I need to build my own. I also don't want to use this issue as a discussion board. Do you know of any communities / places I can go to discuss this topic more in a cisco context?

brmcdoug commented 3 years ago

You're right, this isn't a great discussion board. You could try https://developer.cisco.com/yangsuite/ Also feel free to email me directly: brmcdoug@cisco.com