cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
796
Views
10
Helpful
4
Replies

Access service parameters right before the service is deleted

AnhTrinh
Level 1
Level 1

Hello,

 

I have an L3VPN service that has a leaf called "service_prefix". During service CREATE operation, that leaf will get the value from an IP Prefix entered by the user.  When I delete the entire service (from NSO CLI or GUI), I want to get the value of that "service_prefix" leaf so I can write some updates to an external system.

 

Is there any way that I can access the service parameters right before it gets deleted (during the DELETE operation)?

 

Appreciate any help.

 

1 Accepted Solution

Accepted Solutions

Hi,
Yes that is the case the service is deleted before the function is called.

You need to use the opaque or in python proplist parameter. Copy everything you want to save into that, it is retained even on deletion.

Stefano

View solution in original post

4 Replies 4

tcragg1
Cisco Employee
Cisco Employee

In the standard python service code, there are pre-modification and post-modification callback functions that are commented out by default that allow you to execute code either before or after a change. One of the arguments that these functions take is "op", or the opcode for the change, which is 2 for a service deletion. If you uncomment one of these callback functions in the service python code and put the code to write the data to the external system in an "if op == 2" statement in one of these callbacks, it should accomplish what you are after.

 

One caveat is that I don't believe this method can distinguish between a dry-run and an actual configuration change - the pre-modification and post-modification callback functions will be triggered by both dry-runs and actual service deletions.

Thanks for the suggestion!

 

I've actually tried that method. I use the ncs.maagic.cd(root, kp) to try access the service parameters from there. Here is my pre-modification function:

 

def cb_pre_modification(self, tctx, op, kp, root, proplist):

  if op == 2:

    service = ncs.maagic.cd(root, kp)

    service_prefix = service.service_prefix

 

However, when my service is deleted I get this log: 

<ERROR> 12-Aug-2021::10:06:21.450 l3vpn-test ncs-dp-1105297-l3vpn-test:main-1-th-29765: - '{vpn1} not in /ncs:services/l3vpn-test:l3vpn-test'

 

Seems like my service {vpn1} is not accessible anymore?

Hi,
Yes that is the case the service is deleted before the function is called.

You need to use the opaque or in python proplist parameter. Copy everything you want to save into that, it is retained even on deletion.

Stefano

Thanks a lot! This is what I need.