load_xml
in https://github.com/robshakir/pyangbind/blob/master/pyangbind/lib/serialise.py, under the class pybindIETFXMLDecoder is defined the function load_xml load_xml(d, parent, yang_base, obj=None, path_helper=None, extmethods=None)
Actually I am trying to use it, however I am stuck because I do not know of what type is "d"
Thanks in advance
I think it is an object element created with lxml.objectify. see here lxml objectify if you look at the load() method above it in pybindIETFXMLDecoder shows how to create the object from an xml string.
Thanks @igrush Here you have an example in case someone is wondering how to do this:
import os
from binding import *
from lxml import objectify
from pyangbind.lib.serialise import pybindIETFXMLDecoder
...
f = open("terminal-device.xml", "r")
xml_string = f.read()
xml_obj = objectify.fromstring(xml_string)
new_oclr = pybindIETFXMLDecoder.load_xml(xml_obj, binding, "openconfig_terminal_device")
Hi everyone,
Thank you for the example. Unfortunately, I am still not able to use the pybindIETFXMLDecoder. My understanding is that I can load XML into a class. For example when I get the openconfig-interface configuration from a device via ncclient. What I did so far:
pyang --plugindir $PYBINDPLUGIN -f pybind -o openconfig_interfaces.py openconfig/release/models/interfaces/openconfig-interfaces.yang -p yang/standard/ietf/RFC/ -p openconfig/release/models/types -p openconfig/release/models
Then I load the interfaces from a device:
from openconfig_interfaces import openconfig_interfaces
from ncclient import manager
def get_interfaces():
interface_obj = openconfig_interfaces()
filter = pybindIETFXMLEncoder.serialise(interface_obj.interfaces)
with manager.connect(host='test', port=830, username='test', password='test', hostkey_verify=False) as m:
config = m.get_config(source='running', filter=('subtree', filter)).data_xml
tree = ET.fromstring(config)
Now I would like to work with the interface data. How can I do that?
Thank you Remo
The code example does indicate how to take in the XML data obtained from the device, and then work with the Python object.