cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1340
Views
1
Helpful
7
Replies

Issue Create Route policy for NCS5500 V7. XR netconf via Python in NSO

gkhaled
Level 1
Level 1

Hello,

is there any one had the problem when try to create anew route policy for the NCS5500 XR netconf via Python in NSO?

i try to put some logic in python till can can create new route policy as like below example :

 

route-policy EBGP_PE1_IN 

  if extcommunity rt matches-any (65535:400400) then              

    set extcommunity rt (65102:104104) additive          

    set community (1:1) additive                     

    set local-preference 300                            

    pass                                 

  elseif extcommunity rt matches-any (65535:400200) then

    set extcommunity rt (65102:102003) additive

    set extcommunity rt (65102:102004) additive

    set community (1:1) additive

    pass

  endif

  pass

end-policy

 

but the problem that when try to deploy the package , it seems created on NSO but without devices and no configuration deployed on the device .

so is there any one know why the package does not deploy on the devices ?

 

1 Accepted Solution

Accepted Solutions

Hello ,

 

Since it’s working .Can you mark it as solved ?

View solution in original post

7 Replies 7

Nabsch
Spotlight
Spotlight

Hello,

 

Can you put your python code ? You can enable trace on the device that might help you to find the root cause.

here are my python code 

def cb_create(self, tctx, root, service, proplist):
self.log.info('Service create(service=', service._path, ')')
self.log.info(service.device)
# starting with empty value
val = ''
# looping the list of extcommunity
#for comm in service.device:

DEVs = []
for DEV in service.device:

DEVs.append(DEV.dev)
self.log.info(DEVs)
for rpl in DEV.route_policies:
for comm in rpl.extcommunity:
self.log.info("{} {} {} ".format(type(service.device),len(service.device),comm))

val += f"""route-policy {rpl.route_policy_name}
if extcommunity rt matches-any ({comm.rt_match_as}:{comm.rt_match_id1}) then
set extcommunity rt ({comm.bgp_rt_set_local_as}:{comm.bgp_rt_set_id1}) additive
set community ({comm.bgp_community_as}:{comm.bgp_community_id}) additive
set local-preference {comm.bgp_local_preference}
pass
elseif extcommunity rt matches-any ({comm.rt_match_as}:{comm.rt_match_id2}) then
set extcommunity rt ({comm.bgp_rt_set_local_as}:{comm.rt_set_id2}) additive
set extcommunity rt ({comm.bgp_rt_set_local_as}:{comm.rt_set_id3}) additive
set community ({comm.bgp_community_as}:{comm.bgp_community_id}) additive
pass
endif
pass
end-policy\n"""
self.log.info(val)

with ncs.maapi.Maapi() as m:
with ncs.maapi.Session(m, 'admin', 'python'):
with ncs.maapi.single_write_trans('admin', 'python', groups=['ncsadmin']) as t:
root = ncs.maagic.get_root(t)
for dev in DEVs:
self.log.info(dev)
device_list = root.devices.device[dev]
self.log.info("Device to read : " + device_list.name)
RPL = device_list.config.Cisco_IOS_XR_policy_repository_cfg__routing_policy.route_policies.route_policy
RPL_create = RPL.create(rpl.route_policy_name).rpl_route_policy
self.log.info("create new RPL : " + rpl.route_policy_name)

vars = ncs.template.Variables()
vars.add('VAL', val)
template = ncs.template.Template(service)
template.apply('route_policy_config-template', vars)
self.log.info("deploy service ")

 

 

 

Can you reformat your code ?

How i can do that ?

Nabsch
Spotlight
Spotlight

You have  to click on insert code 

example-nso.jpg

 

Concerning your code , you made some mistake. You create the RPL but you in a transaction that you had never apply ( commit) so the RPL is not created. If you try to add t.apply() it will fails because you are inside cb_create so you already acquire cdb lock.

I suggest you to create your RPL with a template and you apply your template inside your loop so you can create all the RPL that you want instead of doing 

    with ncs.maapi.Maapi() as m:
    with ncs.maapi.Session(m, 'admin', 'python'):
    with ncs.maapi.single_write_trans('admin', 'python', groups=['ncsadmin']) as t:
    root = ncs.maagic.get_root(t)
    for dev in DEVs:
    self.log.info(dev)
    device_list = root.devices.device[dev]
    self.log.info("Device to read : " + device_list.name)
    RPL = device_list.config.Cisco_IOS_XR_policy_repository_cfg__routing_policy.route_policies.route_policy
    RPL_create = RPL.create(rpl.route_policy_name).rpl_route_policy
    self.log.info("create new RPL : " + rpl.route_policy_name)

 

 

It would be something like this 

vars = ncs.template.Variables()
template = ncs.template.Template(service)    
for dev in DEVs:
    self.log.info(dev)
    vars.add("DEVICE",dev)
    vars.add("RPL",rpl.route_policy_name)
    self.log.info("create new RPL : " + rpl.route_policy_name)

Hello 

it is worked fine now after that change , many thanks

Hello ,

 

Since it’s working .Can you mark it as solved ?

Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?