utm_medium=referral&utm_source=cc-ribbon&utm_campaign=ST-RMA-4-21 " target="_blank">
Would you like to learn more about how to determine if you need an RMA? - REGISTER TODAY!
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
213
Views
0
Helpful
1
Replies
Mawaheb Kabbara
Cisco Employee

CRUD read issues and syntax

hi, I am trying to write a simple Python program to read BGP config from my router and i keep getting errors as follows:

 

/home/mkabbara/env/bin/python3 /root/PycharmProjects/pythonProject/test3.py
Traceback (most recent call last):
File "/root/PycharmProjects/pythonProject/test3.py", line 22, in <module>
result = crud.read_config(self='172.16.1.71', provider=sp_instance, read_filter=bgp)
File "/home/mkabbara/env/lib64/python3.6/site-packages/ydk/services/crud_service.py", line 63, in read_config
return _crud_read(provider, read_filter, True, self._crud.read_config)
AttributeError: 'str' object has no attribute '_crud'

Process finished with exit code 1

 

 

the python program looks like this

 

from ydk.models.openconfig import openconfig_bgp
from ydk.providers import NetconfServiceProvider
from ydk.services import CRUDService as crud
from ydk.types import Filter, Config
from ydk.models.openconfig import openconfig_bgp, openconfig_interfaces

sp_instance = NetconfServiceProvider(address='172.16.1.71',
port=830,
username='cisco',
password='cisco',
protocol='ssh')

# First, create the top-level Bgp() object
bgp = openconfig_bgp.Bgp()

# Populate the values for the global config object
bgp.global_.config.as_ = 1
bgp.global_.config.router_id = '172.16.1.71'

# Call the CRUD create on the top-level bgp object
# (assuming you have already instantiated the service and provider)
result = crud.read_config(self='172.16.1.71', provider=sp_instance, read_filter=bgp)

 

I guess i am not using the crud.read service properly.

What should these keys be set to:

self=?

provider (i guess this is clear)

read_filter (this is clear)

 

what do you think the issue is

1 REPLY 1
alexstev
Cisco Employee

Hi @Mawaheb Kabbara,

 

There are a lot of basic and intermediate examples here --> CiscoDevNet-ydk-py-samples

There is even a special section just for Crud

Finally, there is some very good explanation given during this Cisco Live Demo - YDK and Model Driven
Programmability with Python 

 

Hope this helps!

 

Content for Community-Ad

This widget could not be displayed.