Closed Dulin0411 closed 9 months ago
I suggest you check the documentation and examples. The Issues are intended to report bugs and missing features. How to use the library can be found in the documentation and examples, and also online searching for code that uses pyangbind.
interfaces
, like next_hops
in https://github.com/robshakir/pyangbind/blob/master/README.md, is an ordered dict of elements. You need to add an element, which later can be retrieved by index.
interfaces = binding.ietf_interfaces().interfaces
type(interfaces)
<class 'pyangbind.lib.yangtypes.YANGDynClass.<locals>.YANGBaseClass'>
help(interfaces)
...
interfaces.interface.add(name="lo0")
interfaces.interface.add(name="lo1")
print(interfaces.interface["lo0"])
OrderedDict([('name', <property object at 0x7c0303ced2c0>), ('description', <property object at 0x7c0303ced270>), ('type', <property object at 0x7c030384d270>), ('enabled', <property object at 0x7c030384d180>), ('link_up_down_trap_enable', <property object at 0x7c030384d2c0>)])
pybindIETFXMLEncoder.serialise(interfaces.interface["lo1"])
'<interface xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">\n <name>lo1</name>\n</interface>\n'
Sorry, may be I didn't describe clearly. There is difference between filter by leaf node and filter by leaf value(as you writed).
There is an example for filter by leaf node, Can get all interfaces name:
`
`
Is your intention to write the NETCONF Filter expression, in XML, using pyangbind?
I wonder if your question has to do with NETCONF, and not with pyanbind.
I would suggest to write the filter you need in XML and attempt to reproduce it with pyangbind.... but maybe it is also possible to create the XML filter using https://docs.python.org/3/library/xml.etree.elementtree.html#module-xml.etree.ElementTree. You can define the XML structure as per the filter you need, and dump it in a string.
https://docs.python.org/3/library/xml.etree.elementtree.html#building-xml-documents
Hi,
I want to user pyangbind to get leaf node, but I don't know how to realize it?
use the fllowing code can realize filter by contrainer:
interfaces = ietf_interfaces().interfaces
filter = pybindIETFXMLEncoder.serialise(interfaces)
But same way don't take effect on leaf node.
Thanks