cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
438
Views
10
Helpful
5
Replies
Luis Perez
Beginner

YDK issues Lab 10.8 DEVASC ELearning Training Use Cisco SDK and Python for Automation Scripting

Problems executing python script in this specific lab of DEVASC training course, when you instantiate CRUDService() it fails with messages: "TypeError: ydk_.services.CRUDService.__init__() must be called when overriding __init__"  

 

Ive tried to make changes inside of the crud_service, executor_service and netconf_service python files as mentioned here https://github.com/ygorelik/ydk-gen/commit/2c53f5dc736d73064c03dc1c404982d1c9011d64 actually the previous issue dissapear but now is showing issus related with the read method of the CRUDService object. 

 

The python script executed is attached.

 

Someone knows which steps we have to take in account to make this script suscessfully work?

 

 

5 REPLIES 5
yangorelik
Participant

Hi Luis

When building model you must always start from the top level entity and keep in mind that container and list classes has already been instantiated in parent class. Your script should be:

from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native as xe_model # you had error in this line

# CSR1kv1 Credentials
ip = '10.0.0.20'
port_n = 830
user = 'cisco'
paswd = 'cisco'
proto = 'ssh'

if __name__ == '__main__':
# open the connection with Netconf server
provider = NetconfServiceProvider(address=ip, port=port_n, username=user, password=paswd, protocol=proto)

# initialize CRUD Service
crud = CRUDService()

# create a new instance of Native object
xe_native = xe_model.Native() # always start from top level entity
xe_interfaces = xe_native.interfaces # object 'interfaces' has already been instantiated

# read the interfaces with the help of read function
interfaces_data = crud.read(provider, xe_interfaces)

# print the primary address of the fifth gigabitethernet interface
print(interfaces_data.gigabitethernet[4].ip.address.primary.address)
exit()
Yan Gorelik
YDK Solutions

Have the same problem when initializing CRUDService:

 

Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
>>> from ydk.services import CRUDService
>>> crud = CRUDService()
TypeError: ydk_.services.CRUDService.__init__() must be called when overriding __init__

 

Please your help to solve this problem.

 

Try this

 

https://github.com/ygorelik/ydk-gen/commit/2c53f5dc736d73064c03dc1c404982d1c9011d64 

 

I made the changes inside of the crud_service.py file suggested and that solve the issue

Thanks Yan i tried again only modifying the crud_service.py file as mentioned here https://github.com/ygorelik/ydk-gen/commit/2c53f5dc736d73064c03dc1c404982d1c9011d64 and without any change in the code the scritp works as expected

Hello Luis and Jose

Since the 0.8.5 merge to upstream (still officially not released) I have fixed few bugs including the above one. Therefore I suggest you to use master branch from my fork. The installation is very simple:

git clone https://github.com/ygorelik/ydk-gen.git

cd ydk-gen

./install_ydk.sh --core

For YDK test drive I suggest to use docker:

docker run -it ydksolutions/ydk-gen

Yan Gorelik
YDK Solutions
Content for Community-Ad

This widget could not be displayed.