08-12-2021 03:25 AM
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.
Solved! Go to Solution.
08-12-2021 05:08 AM
08-12-2021 03:42 AM
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.
08-12-2021 03:53 AM
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?
08-12-2021 05:08 AM
08-12-2021 06:59 AM
Thanks a lot! This is what I need.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide