when writing some application for reading configuration of device is as follows:
- Create root object of the hierarchy. (as en example from Cisco_IOS_XR_infra_syslog_cfg module create Syslog() )
- Put the object to crud.read method as a parameter
- iterate / take what is needed from the crud read object output.
But when trying to want to take all routes (dynamic/static/connected) and its next hop from Cisco_IOS_XR_ip_rib_ipv4_oper model getting error. The LAB XR that has 10000 routes across several VRFs. To create the Rib() root object from rib oper model and pass it to crud read method, it takes 10 minutes to take the output. And the output contains lots of information which is not needed. What is needed is just all the routes from all VRFs and its next hops, nothing more. Is it somehow possible to get just these. Tried to go down the Cisco_IOS_XR_ip_rib_ipv4_oper hiearchy and just pass to crud.read the deep nested object (Rib.Vrfs.Vrf.Afs.Af.Safs.Saf.IpRibRouteTableNames.IpRibRouteTableName.Routes.
Route
). But always hit the exception (attachment). Or is there some other approach how to accomplish that the XR device will not send me all the info in Cisco_IOS_XR_ip_rib_ipv4_oper model and just the routes and its next hop.
Tried many combinations to pass just the final Route() class to crud.read function. During that noticed that can go down to class till you hit the YList type. For example in Cisco_IOS_XR_ip_rib_ipv4_oper this works OK: rib_oper = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf(). But when you try to pass to method this: rib_oper = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs() then got the same exception
Basically, when using nested classes with lists as parents, you need to populate the keys for the parent lists. Try the below:
Note: You may need a workaround for the error mentioned here:
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_rib_ipv4_oper
from ydk.providers import NetconfServiceProvider
rib = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib()
vrf = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf()
vrf.vrf_name='default'
af = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af()
af.af_name = 'IPv4'
saf = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af.Safs.Saf()
saf.saf_name='Unicast'
table_name = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af.Safs.Saf.IpRibRouteTableNames.IpRibRouteTableName()
table_name.route_table_name = 'default'
route = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af.Safs.Saf.IpRibRouteTableNames.IpRibRouteTableName.Routes.Route()
route.address='0.0.0.0'
table_name.routes.route.append(route)
saf.ip_rib_route_table_names.ip_rib_route_table_name.append(table_name)
af.safs.saf.append(saf)
vrf.afs.af.append(af)
rib.vrfs.vrf.append(vrf)
provider = NetconfServiceProvider(address="10.33.94.147",
port=830,
username="admin",
password="admin",
protocol="ssh",
timeout = 600)
# create CRUD service
crud = CRUDService()
rib_oper = crud.read(provider, route)
print(rib_oper)
provider.close()
Note: If still facing issues it may Look like you are still using the top level object as the filter used for crud.read. Can you try changing the crud.read call to the below.
rib = crud.read(provider, route)
You're in luck as a wild card for all route addresses is available . If we just do not set the route address, it fetches all the routes.
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_rib_ipv4_oper
from ydk.providers import NetconfServiceProvider
rib = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib()
vrf = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf()
vrf.vrf_name='default'
af = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af()
af.af_name = 'IPv4'
saf = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af.Safs.Saf()
saf.saf_name='Unicast'
table_name = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af.Safs.Saf.IpRibRouteTableNames.IpRibRouteTableName()
table_name.route_table_name = 'default'
route = Cisco_IOS_XR_ip_rib_ipv4_oper.Rib.Vrfs.Vrf.Afs.Af.Safs.Saf.IpRibRouteTableNames.IpRibRouteTableName.Routes.Route()
#route.address='0.0.0.0' # Do not set the route address
table_name.routes.route.append(route)
saf.ip_rib_route_table_names.ip_rib_route_table_name.append(table_name)
af.safs.saf.append(saf)
vrf.afs.af.append(af)
rib.vrfs.vrf.append(vrf)
provider = NetconfServiceProvider(address="localhost",
port=1220,
username="admin",
password="admin",
protocol="ssh",
timeout = 600)
# create CRUD service
crud = CRUDService()
rib_oper = crud.read(provider, route)
print(rib_oper)
provider.close()
- But this fetches also all information from the whole Route() object and want just the address from all routes No wildcard for that...
Set the address of the Route object to an instance of the special type “ydk.types.Empty”
Comments
0 comments
Please sign in to leave a comment.