Open hyberdk opened 2 weeks ago
A few clarification questions:
What is your YANG model, or an extract of it? This YANG model is what will produce the Python code in pyangbind and, as far as I read the docs, also ykd-gen. Is it https://github.com/YangModels/yang/blob/main/vendor/cisco/xe/1671/Cisco-IOS-XE-native.yang ?
Once you get and use your Python classes, you want to use the generated classes to create a Python object that, when serialized in XML, produces the output you desire, is this correct? What is the Python code you have tried?
I do not have extensive experience with NETCONF or XML, but I will try my best to help.
Hey @JoseIgnacioTamayo,
thanks a lot for your reply. Yes that is the model I am using (although a slightly newer version). For the access-lists, this model augments the native model with acls: https://github.com/YangModels/yang/blob/main/vendor/cisco/xe/1671/Cisco-IOS-XE-acl.yang
Once you get and use your Python classes, you want to use the generated classes to create a Python object that, when serialized in XML, produces the output you desire, is this correct?
correct
What is the Python code you have tried?
I haven't gone that far yet. I was trying to read up on the docs, and I am pretty sure I can do the python code and generate both the XML and JSON representation of the model. which is fine.. essentially when I send it to the device, I need to wrap it in netconf edit-config tags..
something like
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<edit-config>
<target>
<running/>
</target>
<config>
<!-- yang data here. -->
</config>
</edit-config>
</rpc>
I dont think pyangbind can do the entire request for me, however it would be nice if it could. do you know?
The problem is that the "default" edit-config is a "merge", where it merges the new config into the existing.. this is where the operation="replace" attribute comes in, as it instructs the device in not merging the new config, but replace it entirely (removing any additional config)..
ydk-gen can do the entire process start-to-end, including setting the operation attribute, but to be honest ydk-gen is poorly maintained, so I was hoping that pyandbind would be able to do something similar for me..
I hope it makes sense..
Esben
Upon reading a bit, I think pyangbind cannot help you here.
The Operation setting, within a
pyangbind works with the Cisco YANG Model, in which there is no notion of 'operation'. The Cisco-IOS-XE-acl.yang says that there is a container 'extended' keyed by 'name'.
What you could do is to use the pyangbind-generated Python classes to serialize the XML payload you need, and use something like python xml.etree to inject the attribute 'operation=replace' at the right part of the XML tree, and wrap it all in a NetConf XML
Hope that helps.
Im trying out pyangbind, but there are something that I cannot wrap my head around.
I would like to define the attribute operation="replace" as defined in https://datatracker.ietf.org/doc/html/rfc6241#section-7.2
what I want is xml that looks something like this:
but I cannot for the heck of it, figure out how to do it.. I have been playing around with YDK-GEN and there you can set a "YFilter" property that is reflected in the xml output
See this: https://ygorelik.github.io/ydk-gen/api/filters.html#ydk.filters.YFilter
is there a similar thing I can set in pyangbind?
Please RFTM me, I cannot find it ;-)