Showing results for 
Search instead for 
Did you mean: 

Cisco Employee

bgp_oper unable to read for a particular vrf_name


I need to get only vrf operational data under BGP, but am getting an error when I try to read it. Please guide me on how I can get the required output


from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ipv4_bgp_oper as xr_ipv4_bgp_oper
#BGP instances data: Instance specific BGP data
        bgp_oper_obj = xr_ipv4_bgp_oper.Bgp()
        bgp_oper_instance_list = bgp_oper_obj.Instances()
        bgp_oper_instance_list_obj = bgp_oper_instance_list.Instance()
        bgp_oper_active_instance_obj = bgp_oper_instance_list_obj.InstanceActive()
        bgp_oper_active_instance_vrf_list = bgp_oper_active_instance_obj.Vrfs()
        bgp_oper_active_instance_vrf_list_obj  = bgp_oper_active_instance_vrf_list.Vrf()
        bgp_oper_active_instance_vrf_list_obj.vrf_name = "TEST-VRF"
I am trying to get oper data for TEST-VRF vrf.
i get the below error when I run the script.

Traceback (most recent call last):
File "", line 149, in <module>
bgp_oper_main(device_netconf ,device_input)
File "", line 108, in bgp_oper_main,bgp_oper_active_instance_vrf_list_obj)
File "/usr/local/lib/python3.5/dist-packages/ydk/services/", line 63, in read
top_filters = _get_top_level_entity(filters, provider.get_session().get_root_schema())
File "/usr/local/lib/python3.5/dist-packages/ydk/entity_utils/", line 216, in _get_top_level_entity
data_node = get_data_node_from_entity(top_entity, root_schema)
RuntimeError: YInvalidArgumentError: ancestor for entity cannot be nullptr as one of the ancestors is a list. Path: vrfs
Disconnected from device

Rising star

Hello arynair

1. When building model objects you have to keep in mind that all container and list related objects are already initialized in the parent object instances. As example for your script, the instances container object under bgp_oper_obj has already been instantiated and can be referenced as bgp_oper_obj.instances.

2. When building a list you have to instantiate list element objects and explicitly set all keys of the element. Then you add the list element object to the list object, which is automatically instantiated as container objects.

Considering the above notes your object building would look like this:

from import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ipv4_bgp_oper as xr_ipv4_bgp_oper

import logging

def enable_logging(level):
log = logging.getLogger('ydk')
handler = logging.StreamHandler()
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")

def build_bgp_vrf_obj():
bgp_oper_obj = xr_ipv4_bgp_oper.Bgp()

bgp_oper_instance_list_obj = xr_ipv4_bgp_oper.Bgp.Instances.Instance()
bgp_oper_instance_list_obj.instance_name = 'default'

bgp_oper_active_instance_vrf_list_obj = xr_ipv4_bgp_oper.Bgp.Instances.Instance.InstanceActive.Vrfs.Vrf()
bgp_oper_active_instance_vrf_list_obj.vrf_name = "TEST-VRF"
return bgp_oper_instance_list_obj

if __name__ == '__main__':


provider = NetconfServiceProvider(

crud = CRUDService()
bgp_vrf_obj = build_bgp_vrf_obj()
vrf_oper =, bgp_vrf_obj)
Yan Gorelik
YDK Solutions

Hi Yan,


Facing Ycode error when trying to read all bgp oper info with top level object. (No filter)

The code breaks with same error.

bgp_oper_obj = xr_ipv4_bgp_oper.Bgp()

I mean when only this line is in the code, not including others.


Couldn't fetch child entity extended-nh-encoding-capability-suppressed-info in parent /Cisco-IOS-XR-ipv4-bgp-oper:bgp/config-instances/config-instance[instance-name='default']/config-instance-default-vrf/entity-configurations/entity-configuration[1]/af-independent-config!
Traceback (most recent call last):
File "", line 165, in <module>
bgp_oper_main(device_netconf ,device_input)
File "", line 122, in bgp_oper_main
a =,bgp_oper_instance_list_obj)
File "/usr/local/lib/python3.5/dist-packages/ydk/services/", line 65, in read
read_top_entity =, top_filters)
File "/usr/lib/python3.5/", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/ydk/errors/", line 82, in handle_runtime_error
File "/usr/local/lib/python3.5/dist-packages/ydk/errors/", line 54, in _raise
exec("raise exc from None")
File "<string>", line 1, in <module>
ydk.errors.YCoreError: Couldn't fetch child entity 'extended-nh-encoding-capability-suppressed-info' in parent /Cisco-IOS-XR-ipv4-bgp-oper:bgp/config-instances/config-instance[instance-name='default']/config-instance-default-vrf/entity-configurations/entity-configuration[1]/af-independent-config



Sorry, I cannot help you being outside Cisco, because I do not have access to your router and public XR sandbox does not have BGP configuration.

Yan Gorelik
YDK Solutions

What XR bundle version are you using?  What XR version is running on the device?

xr version on device is 7.0.2, xr bundle version on ydk is 6.6.2


 I am having similar trouble with the rib-ipv4-oper module as well:

attaching log for the filter, and output received before the code breaks. I am trying to retrieve the route information, so it would be great if could get help in bypassing the error

I could not reproduce your issue with YDK-0.8.5. PFA my script and log files.

Please note that there were multiple bug fixes since 0.8.3, which potentially could affect the results.

I suggest you upgrade your YDK (currently available only on GitHub) and repeat your tests. Alternatively you can try the tests on Docker.

Yan Gorelik
YDK Solutions

Hi Yang, 

I am facing the same issue when running the script on docker for ydk 0.8.5

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_rib_ipv4_oper as xr_ip_rib_ipv4_oper 
from ydk.providers import NetconfServiceProvider
from import CRUDService
import logging
ipv4_rib_oper_obj = xr_ip_rib_ipv4_oper.Rib()
ipv4_vrfs_list = ipv4_rib_oper_obj.Vrfs()
ipv4_vrfs_list_obj = ipv4_vrfs_list.Vrf()
ipv4_vrfs_list_obj.vrf_name = "TEST-VRF",ipv4_vrfs_list)
the error log that was attached is an output to this script structure when running it on iosxr 7.0.2

ydk (0.8.5)
ydk-models-cisco-ios-xr (6.6.3.post1)
ydk-models-ietf (0.1.5.post2)
ydk-models-openconfig (0.1.8)
ydk-service-gnmi (0.4.0.post5)


this is the current environment


and error is :ydk.errors.YCoreError: Couldn't fetch child entity 'l2-info' in parent /Cisco-IOS-XR-ip-rib-ipv4-oper:rib/vrfs/vrf[vrf-name='default']/afs/af[af-name='IPv4']/safs/saf[saf-name='Unicast']/ip-rib-route-table-names/ip-rib-route-table-name[route-table-name='default']/routes/route[address=''][prefix-length='0']/route-path/ipv4-rib-edm-path[1]


PFA the logs

There are some errors in your script (same as mentioned in my first post), but I don't think that will affect the error. Anyway, it is worth of trying.
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_rib_ipv4_oper as xr_ip_rib_ipv4_oper 
from ydk.providers import NetconfServiceProvider
from import CRUDService
import logginglog = logging.getLogger('ydk')log.setLevel(logging.INFO)ipv4_rib_oper_obj = xr_ip_rib_ipv4_oper.Rib()
# ipv4_vrfs_list = ipv4_rib_oper_obj.Vrfs() # THE LIST HAS BEEN ALREADY INITIALIZED IN THE Rib CONSTRUCTOR
ipv4_vrfs_list_obj = xr_ip_rib_ipv4_oper.Rib.Vrfs.Vrf() # Correct initialization of the iner class
ipv4_vrfs_list_obj.vrf_name = "TEST-VRF"
ipv4_rib_oper_obj.vrfs.vrf.append(ipv4_vrfs_list_obj) # !! MUST ADD LIST ELEMENT TO THE LIST

vrf_oper =, ipv4_vrfs_list_obj)  # REQUESTING SPECIFIC VRF OPER DATA

!!Before running the script please remove all YANG models in temporary repository under $HOME/.ydk/*. That will enforce model download from device, which will ensure match between the model and received RPC.

Yan GorelikYDK Solutions
Yan Gorelik
YDK Solutions

hi Yan,

i was not able to resolve the issue and used alternate method using ncclient



Recognize Your Peers
Content for Community-Ad