11-12-2020 05:57 AM
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)?
11-19-2020 12:30 AM
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,
11-19-2020 02:39 AM
Hello, I solved
Thanks
11-20-2020 12:37 AM
Great news! Feel free to add your solution and marked it as the accepted one for future readers of the thread.
Best regards
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