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

select service instances by partial key in java

Hi all, I need a help to implement a CISCO NSO service in java: the task is to select service instances by partial key. For example, I have a NSO service with a composite key (olt-name and svlan) and I need to implement another service to read instances of the previous one by partial key (olt-name). Can anybody tell me what is java API or a Navu library I can use to extract service instances corrisponding to this kind of selection (partial key)?

3 Replies 3

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

I am not sure I understand 100% what you are trying to achieve however there is a way to select any part of the YANG tree using the com.tailf.com.Maapi.xpathEval function.

You can pass it an xpath as the expr parameter that will go something like:

/namespace:service[namespace:olt-name='<OLT-NAME>']

You can read more about the method in the Java API.

 

I myself do not use too much the Java API but here is an example in python that you could get inspiration from

 

import ncs
m=ncs.maapi.Maapi()
session = ncs.maapi.Session(m, 'admin', 'system')
t = m.start_read_trans(ncs.RUNNING)
path = "/services/test:test/members[members='test-member']/../name"
def f(x,y):
"""
Dummy function to print but should do something smart here
"""
print(x, y)
t.xpath_eval(path, f, None, "/")

 

This snippet will go through all my test services and look for the ones that have test-member as an entry in the members leaf-list and will return the name of my service. If you make f store the Xpath somewhere you can then reuse them later. (Here I am only printing the values)

 

Regards,

Hello, I solved

Thanks

Great news! Feel free to add your solution and marked it as the accepted one for future readers of the thread.

 

Best regards