YDK works like charm for my IOS-XR devices. Created several applications and they all works. Then tried to generate python API/Sphinx docs for Junos Yang models, that also worked like charm.
However cannot run a single application against Junos devices . Trying to get syslog configuration from device but all the values are None, however device is properly configured. In attachment (debug.txt) you can find output while running the application with debugging on (verbose mode). Everything passed and you can even see correct values in the xml data (for example <log-rotate-frequency>10</log-rotate-frequency>) but seems crud read operations doesn't pass these values to python object.
In this line in your .py filenoticed a typo:
print (syslog_configuration.__dic__)
It should be __dict__, I think. Can you fix that and see if it changes anything?
From looking at the log, it seems that the server is returning the XML data and YDK is decoding the XML data into a python object, which you are trying to print out as <obj>.__dict__
Perhaps, a better way to process the YDK python object would be to iterate through it and print out the children. See this CRUD read sample for an example.
Another option could be to encode the YDK python object back into XML using the codec service. See this sample for example.
Just have a couple comments/suggestions. In your app, you are reading the entire device configuration. So, the result of the crud read operation will be instances of the class: ydk.models.configuration.Configuration(). To know what the attributes of this class are, you can either look at the documentation, which you can generate using generate.py, or look at the class itself (configuration.py) which contains doc strings with information about the class attributes and types of each attribute. Then you can print out the data in a human readable format, which is what your app is presumably trying to do.
For example, try the below code and modify it as you desire to print the read data:
def testJunos(configuration):
# Print attributes
print ('Configuration version: {}'.format(configuration.version)) # System version
print ('System host name: {}'.format(configuration.system.host_name)) # Hostname
print ('System login message: {}'.format(configuration.system.login.message)) # Login message
print()
# Iterate the configuration.system.login.user YList and print out members
for user in configuration.system.login.user:
print('User name: {}'.format(user.name))
print('User uid: {}'.format(user.uid))
print('User class: {}'.format(user.class_))
print()
# By default all the attributes are set to None, so you may need to check for this
if configuration.system.syslog.log_rotate_frequency is not None:
print('Syslog log rotate frequency: {}'.format(configuration.system.syslog.log_rotate_frequency))
# Iterate the configuration.system.syslog.user YList and print out members
for syslog_user in configuration.system.syslog.user:
print('Syslog user name: {}'.format(syslog_user.name))
for contents in syslog_user.contents:
print('Syslog contents name: {}'.format(contents.name))
print('Syslog contents emergency? {}'.format(contents.emergency == None))
The issue here is that the crud.read object (syslog_configuration in my code) is just empty no matter what you perform. Seems like the XML is not parsed back to python even though we can see from the debugging output that the XML data are sent properly. Wrote several applications for XR (using xr models) with YDK and that works just great. Don't have any explanation why its always empty. Already using the documentation that is generated with ydk-gen for Junos, that is not the issue.
Do you have please some other ideas how can I troubleshoot the CRUD object if it reads the xml.
Notice that there are some weird inconsistencies in the namespaces being used in the YANG model, the <get> RPC request and the RPC reply.
see two separate namespaces for these:
- in the yang model (from which the YDK model API is generated): 'http://yang.juniper.net/yang/1.1/jc'
- in the <get> RPC request (from your debug log): 'http://yang.juniper.net/yang/1.1/jc'
- in the RPC reply (from your debug log): 'http://xml.juniper.net/xnm/1.1/xnm'
However, per the netconf/yang RFCs, the namespaces should remain consistent across all the above. For some reason, junos seems to diverge from the standard. This is likely the reason why YDK is not able to populate the python object.
edit the _yang_ns.py under "/usr/local/lib/python3.5/dist-packages/ydk/models/junos" to value the junos device returns .
Maybe can be good to implement some exception for this? Just an idea.
YDK-Cpp should already throw an exception in this scenario. YDK-Py should do the same in the next minor release.
Comments
0 comments
Please sign in to leave a comment.