cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
822
Views
5
Helpful
1
Replies

YDK NX-OS

prmalik
Cisco Employee
Cisco Employee

Hi Team,

 

I am able to test some of sample python programs using YDK + XR.  However, getting error while using YDK with NX-OS ?

I tried CRUD read/write it seems to be not working.

Do we have any sample for YDK for NX-OS ?

 

I am testing latest YDK with NX-OS 9.2.1 (Sandbox)

 

Error on using  basic CURD READ on NX-OS

 

#!/usr/bin/env python2

from ydk.models.cisco_nx_os import Cisco_NX_OS_device \
as cisco_nx_os_device
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider

sp_instance = NetconfServiceProvider(address="x.x.x.x",
port=10000,
username='xxxx',
password=''xxx',
protocol='ssh')

 

crud = CRUDService()
system_time=cisco_nx_os_device.System()
system_time = crud.read(sp_instance, system_time)


print system_time.systemuptime

 

 

Error --

ydk.errors.YInvalidArgumentError: Path is invalid: Cisco-NX-OS-device:System

 

Thanks,

Pradeep

1 Reply 1

yangorelik
Spotlight
Spotlight

Hi Pradeep

I found that in the NX-OS 9.2.1 module Cisco-NX-OS-device.yang there is an error in description field in line 102933; it erroneously contains '\' at the end of the line, which confuses libyang YANG parser. This error in the model was fixed in release 9.2.3. In order to address this issue I copied corrected module file to default repository under $USER/.ydk/64.103.37.14/. Then I ran your script and it failed again, but this time due to RPC error. The issue with your script is that it requests entire system config and oper data, and apparently the device choked on it. Then I modified the script to get just one leaf 'systemuptime' and that worked well.

Here is my script:

#!/usr/bin/env python

from ydk.models.cisco_nx_os import Cisco_NX_OS_device as device
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.filters import YFilter

import logging

logger = logging.getLogger('ydk')
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
formatter = logging.Formatter(("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
ch.setFormatter(formatter)
logger.addHandler(ch)

sp_instance = NetconfServiceProvider(address='64.103.37.14', port=10000, username='admin', password='Admin_1234!',)
crud = CRUDService()
system_time = device.System()
system_time.systemuptime = YFilter.read
system_time = crud.read(sp_instance, system_time)

print("System uptime: %s" % system_time.systemuptime)

And results:

(venv) ygorelik@xenial:~/ydk-gen/scripts$ ./get-nx-system.py 
2019-10-29 07:09:32,045 - ydk - INFO - Path where models are to be downloaded: /home/ygorelik/.ydk/64.103.37.14
2019-10-29 07:09:32,055 - ydk - INFO - Connected to 64.103.37.14 on port 10000 using ssh with timeout of -1
2019-10-29 07:09:32,288 - ydk - INFO - Executing CRUD read operation on [Cisco-NX-OS-device:System]
2019-10-29 07:09:32,288 - ydk - INFO - Executing 'get' RPC on [Cisco-NX-OS-device:System]
2019-10-29 07:09:34,067 - ydk - ERROR - Cannot find model with module name 'Cisco-NX-OS-device-deviations'
2019-10-29 07:09:34,112 - ydk - INFO - ============= Sending RPC to device =============
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter><System xmlns="http://cisco.com/ns/yang/cisco-nx-os-device">
<systemUpTime/>
</System></filter>
</get>
</rpc>
2019-10-29 07:09:38,991 - ydk - INFO - ============= Received RPC from device =============
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<data>
<System xmlns="http://cisco.com/ns/yang/cisco-nx-os-device">
<systemUpTime>00:00:00:00.000</systemUpTime>
</System>
</data>
</rpc-reply>

System uptime: 00:00:00:00.000
2019-10-29 07:09:39,289 - ydk - INFO - Disconnected from device

In future tests I encourage you to enable logging to see the details of script execution.

Regards,

Yan

 

Yan Gorelik
YDK Solutions