06-03-2019 08:51 PM
In the python pre_modification, I am trying to check the value of a leaf of the service prior to being deleted. The yang module is with a composite key consisting of three (3) leafs. I am having trouble with getting the service record when trying to pass the values from the keypath passed to the operation. I have tried to pass them in in about any format that I can think of and I keep getting back badly formatted or nonexisting path (8) bad key. Anyone have an example of how to retrieve a service with a composite key?
Solved! Go to Solution.
06-03-2019 11:25 PM - edited 06-03-2019 11:26 PM
Hi,
Please follow the code below,
Option1: Composite keys of service can be accessed using kp[0][0], kp[0][1], kp[0][2].
Option2: Also you can get the reference to service under creation and read the service keys
Like below
new_svc = ncs.maagic.cd(root, str(kp))
@Service.pre_modification def cb_pre_modification(self, tctx, op, kp, root, proplist): ServiceKey = '{},{},{}'.format(kp[0][0], kp[0][1], kp[0][2]) if op != ncs.dp.NCS_SERVICE_DELETE: new_svc = ncs.maagic.cd(root, str(kp)) key = ncs.maapi.Key([new_svc.tail_end_router, new_svc.head_end_router, new_svc.pw_id])
06-03-2019 11:25 PM - edited 06-03-2019 11:26 PM
Hi,
Please follow the code below,
Option1: Composite keys of service can be accessed using kp[0][0], kp[0][1], kp[0][2].
Option2: Also you can get the reference to service under creation and read the service keys
Like below
new_svc = ncs.maagic.cd(root, str(kp))
@Service.pre_modification def cb_pre_modification(self, tctx, op, kp, root, proplist): ServiceKey = '{},{},{}'.format(kp[0][0], kp[0][1], kp[0][2]) if op != ncs.dp.NCS_SERVICE_DELETE: new_svc = ncs.maagic.cd(root, str(kp)) key = ncs.maapi.Key([new_svc.tail_end_router, new_svc.head_end_router, new_svc.pw_id])
06-04-2019 07:22 AM
That actually lead me to what part of my issue is, that I am working on a delete of service and want to do a pre-check prior to the actual delete. What I am seeing is that I am not able to retrieve the service info as it tells me it does not exist. Is there a way to look at the service data in the pre_modifications for a delete request?
09-13-2021 04:11 AM
Hello lightfep1,
Did you find a solution to access the serviceinfo of an instance you want to delete?
I am having a similar issue.
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