cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
445
Views
0
Helpful
1
Replies

CRUD read issues and syntax

Mawaheb Kabbara
Cisco Employee
Cisco Employee

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

Alexander Stevenson
Cisco Employee
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!