cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2104
Views
0
Helpful
3
Replies

Trouble getting service model with composite key

lightfep1
Level 1
Level 1

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?  

1 Accepted Solution

Accepted Solutions

mohamkh7
Cisco Employee
Cisco Employee

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])

 

View solution in original post

3 Replies 3

mohamkh7
Cisco Employee
Cisco Employee

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])

 

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?

Hello lightfep1,

Did you find a solution to access the serviceinfo of an instance you want to delete?
I am having a similar issue.