- Want to READ just extended communities and networks from bgp_oper model. Nothing more. But facing some problem with vrf.vrf_name = READ() object. It works for one VRF if you put the name explicitly it doesn't work with READ() object.
The READ object can be used with non-key leafs. If you want to read only the networks under a BGP instance, please try the below:
bgp = Cisco_IOS_XR_ipv4_bgp_oper.Bgp()
instance = Cisco_IOS_XR_ipv4_bgp_oper.Bgp.Instances.Instance()
instance.instance_name = 'default'
vrf = Cisco_IOS_XR_ipv4_bgp_oper.Bgp.Instances.Instance.InstanceActive.Vrfs.Vrf()
vrf.vrf_name = 'default'
af = Cisco_IOS_XR_ipv4_bgp_oper.Bgp.Instances.Instance.InstanceActive.Vrfs.Vrf.Afs.Af()
af.af_name = Cisco_IOS_XR_ipv4_bgp_datatypes.BgpAddressFamilyEnum.ipv4_unicast
network = Cisco_IOS_XR_ipv4_bgp_oper.Bgp.Instances.Instance.InstanceActive.Vrfs.Vrf.Afs.Af.Networks.Network()
af.networks.network.append(network)
vrf.afs.af.append(af)
instance.instance_active.vrfs.vrf.append(vrf)
bgp.instances.instance.append(instance)
bgp_networks = crud.read(provider, network)
- same error also with network object for vrf default. Could be due to common_attributes was part of network object too.
Traceback (most recent call last):
File "CAD/bgp_oper.py", line 42, in <module>
bgp_routes = crud.read(provider, network)
File "/usr/local/lib/python3.5/dist-packages/ydk/services/crud_service.py", line 150, in read
payload = self._execute_crud_operation_on_provider(provider, read_filter, 'READ', only_config)
File "/usr/local/lib/python3.5/dist-packages/ydk/services/crud_service.py", line 167, in _execute_crud_operation_on_provider
operation
--------------------------------------------
ydk.errors.YPYServiceProviderError: Server rejected request.
error-type: application
error-tag: operation-failed
error-severity: error
error-path: ns1:bgp/ns1:instances/ns1:instance[instance-name = 'default']/ns1:instance-active/ns1:vrfs/ns1:vrf[vrf-name = 'default']/ns1:afs/ns1:af[af-name = 'ipv4-unicast']/ns1:networks/ns1:network
error-message: 'YANG framework' detected the 'fatal' condition 'Operation failed'
OK. Are you able to run a <get> RPC for the same data using netconf. If so do you have the XML snippet for this.
- Able to get list of vrfs, but list of networks is empty.
You're using ncclient correctly (BTW, suggest that you may want to take a look at GitHub - CiscoDevNet/ncc: ncclient scripts and helpers; the script ncc.py provides a way to work with "snippets" of lower-level XML config)
However, the request may not be quite correct. The form you have used only asks the platform to return the element <vrf-name>. Can you instead try something like:
<bgp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-bgp-oper">
<instances>
<instance>
<instance-active>
<vrfs>
<vrf>
<afs>
<af>
<networks>
<network>
<network/>
</network>
</networks>
</af>
</afs>
</vrf>
</vrfs>
</instance-active>
</instance>
</instances>
</bgp>
This should return the inet:ip-prefix for all AFs and networks under all VRFs.
Currently, YDK does not support read filters for nested lists with no keys. We only support not providing the key for the deepest list in the nested hierarchy. We will be adding support for this in the future. This issue is tracking it.
Was trying to retrieve the networks from BGP in the default vrf table .Could understand that because of the bug Need to support read filters for nested lists with no keys · Issue #399 · CiscoDevNet/ydk-gen · GitHub cannot set the value in the last nested class. But even with the workaround unable to retrieve the list of networks.
This is the test code
#!/usr/bin/env python from ydk.services import CRUDService, CodecService, NetconfService, Datastore from ydk.providers import CodecServiceProvider, NetconfServiceProvider from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ipv4_bgp_oper \ as xr_ipv4_bgp_oper from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ipv4_bgp_datatypes \ as xr_ipv4_bgp_datatypes from ydk.types import Empty, YList, YLeafList, DELETE, Decimal64, FixedBitsDict, READ import logging #get operational data for BGP -option 1 bgp1 = xr_ipv4_bgp_oper.Bgp() instance = bgp1.instances.Instance() instance.instance_name = "default" default_vrf = instance.instance_active.default_vrf af = default_vrf.afs.Af() af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamilyEnum.ipv4_unicast network1 = af.networks.Network() #network1.network = "192.168.0.100/32" af.networks.network.append(network1) default_vrf.afs.af.append(af) bgp1.instances.instance.append(instance) # create NETCONF provider provider = NetconfServiceProvider(address="172.16.1.1", port="830", username="cisco", password="cisco", protocol="ssh") # create codec provider codec_provider = CodecServiceProvider(type="xml") #creating crud & codec service crud = CRUDService() codec = CodecService() #read operational data networks = crud.read(provider,network1) print codec.encode(codec_provider,networks) #close session provider.close() codec_provider.close()
try the code below.
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ipv4_bgp_oper as xr_ipv4_bgp_oper from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ipv4_bgp_datatypes as xr_ipv4_bgp_datatypes bgp = xr_ipv4_bgp_oper.Bgp() i = xr_ipv4_bgp_oper.Bgp.Instances.Instance() i.instance_name='default' af = xr_ipv4_bgp_oper.Bgp.Instances.Instance.InstanceActive.DefaultVrf.Afs.Af() af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamilyEnum.ipv4_unicast n = xr_ipv4_bgp_oper.Bgp.Instances.Instance.InstanceActive.DefaultVrf.Afs.Af.Networks.Network() af.networks.network.append(n) i.instance_active.default_vrf.afs.af.append(af) bgp.instances.instance.append(i) result=crud.read(provider,n)
Results in below RPC:
2017-07-25 15:11:02,575 - ydk.services.crud_service - INFO - READ operation initiated 2017-07-25 15:11:02,576 - ydk.providers._provider_plugin - DEBUG - <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:b177072e-68d9-442a-a9c7-1fe478a762ba"> <get> <filter type="subtree"> <bgp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-bgp-oper"> <instances> <instance> <instance-name>default</instance-name> <instance-active> <default-vrf> <afs> <af> <af-name>ipv4-unicast</af-name> <networks> <network/> </networks> </af> </afs> </default-vrf> </instance-active> </instance> </instances> </bgp> </filter> </get> </rpc>
Comments
0 comments
Please sign in to leave a comment.