Subject: Re: [netmod] Fwd: Re: How to grep through a YANG? With grepyang

From: Robert Wilton <[email-masked]>
Date: Tue, 3 Apr 2018 15:37:49 +0100

Hi Ariel,

This looks like an interesting/useful tool.

Have you considered hooking into pyang as a pyang extension?

pyang is one of the defacto standard tools that folks interacting with 
yang often use.  If your aim to get widespread usage of your tool making 
it a pyang extension may be one way to achieve that. E.g. this would 
then allow your tool to generate tree output for selected yang 
subtree(s) nodes that you find, or other nice things.

Thanks,
Rob

On 30/03/2018 15:45, [email-masked] wrote:
> Hi all,
> grepyang has got a new feature: it could grep for a node through a 
> module:
>
> # ./grepyang cancel-commit [email-masked]
> 853:  rpc cancel-commit {
> 854:    if-feature confirmed-commit;
> 855:    description
> 856:      "This operation is used to cancel an ongoing confirmed commit.
> 857:       If the confirmed commit is persistent, the parameter
> 858:       'persist-id' must be given, and it must match the value of the
> 859:       'persist' parameter.";
> 860:    reference "RFC 6241, Section 8.4.4.1";
> 861:
> 862:    input {
> 863:      leaf persist-id {
> 864:        type string;
> 865:        description
> 866:          "This parameter is given in order to cancel a persistent
> 867:           confirmed commit.  The value must be equal to the value
> 868:           given in the 'persist' parameter to the <commit> 
> operation.
> 869:           If it does not match, the operation fails with an
> 870:          'invalid-value' error.";
> 871:      }
> 872:    }
> 873:  }
>
> Now it can grep for a node with a greped node:
>
> # ./grepyang input cancel-commit [email-masked]
> 853:  rpc cancel-commit {
> 862:    input {
> 863:      leaf persist-id {
> 864:        type string;
> 865:        description
> 866:          "This parameter is given in order to cancel a persistent
> 867:           confirmed commit.  The value must be equal to the value
> 868:           given in the 'persist' parameter to the <commit> 
> operation.
> 869:           If it does not match, the operation fails with an
> 870:          'invalid-value' error.";
> 871:      }
> 872:    }
> 873:  }
>
> pyang lacks such features; that's why I have been working on grepyang.
>
> It is out on Github (https://github.com/ariel-anieli/grepyang); feel 
> free to play around with it.
>
> If you find it of any interest, have some remarks, or see it needs 
> enhancements; please,  do so: I will work on the issues.
>
> Regards,
> Ariel
>
> ------------------------------------------------------------------------------- 
>
> This message was sent using EURECOM Webmail: http://webmail.eurecom.fr
>
> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod
> .
>

---

From: [email-masked]
Date: Tue, 03 Apr 2018 16:56:05 +0200

Hi Rob,

My answers inline.

Regards,
Ariel

> Have you considered hooking into pyang as a pyang extension?
Till today, no; grpeyang is still a rush, needing improvements and  
cleanups. You suggested a nice idea, indeed.
> yang often use.  If your aim to get widespread usage of your tool
> making it a pyang extension may be one way to achieve that. E.g. this
> would then allow your tool to generate tree output for selected yang
Thanks for your feedback, Rob. Then, I will read through the code of  
pyang, and check the dependencies, if they are any. Who manages the  
Github repository?
>> grepyang has got a new feature: it could grep for a node through a module:
>>
>> 868:           given in the 'persist' parameter to the <commit> operation.
>> 868:           given in the 'persist' parameter to the <commit> operation.
>> It is out on Github (https://github.com/ariel-anieli/grepyang);   
>> feel free to play around with it.
>>
>> ------------------------------------------------------------------------------- This message was sent using EURECOM Webmail:   
>> http://webmail.eurecom.fr
>>

---

From: Robert Wilton <[email-masked]>
Date: Tue, 3 Apr 2018 16:09:13 +0100

Hi Ariel,

Please see inline ...

> pyang, and check the dependencies, if they are any. Who manages the 
Martin Bjorklund - he is also the author.

Extensions (actually called plugins) don't have to go in the same repro, 
they can be loaded dynamically.

If you want to see an example of a plugin that walks the tree (modifying 
it as it goes) then you could take a look at:
https://github.com/rgwilton/pyang/blob/master/pyang/plugins/ietf_to_state_module.py

This takes a pyang tree and generates an extra legacy  "-state" tree 
from it.

Thanks,
Rob