pyangbind icon indicating copy to clipboard operation
pyangbind copied to clipboard

load_xml

Open Muna24 opened this issue 6 years ago • 3 comments

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

Muna24 avatar Jan 15 '19 14:01 Muna24

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.

igrush avatar Mar 27 '19 13:03 igrush

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")

iicc1 avatar Oct 15 '20 23:10 iicc1

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

rgrueebler avatar Jun 08 '21 04:06 rgrueebler

The code example does indicate how to take in the XML data obtained from the device, and then work with the Python object.

JoseIgnacioTamayo avatar Feb 22 '24 16:02 JoseIgnacioTamayo