cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1205
Views
0
Helpful
2
Replies

Accessing NSO service metadata from Java

previousqna
Level 8
Level 8

Hi all,

Does anyone have sample code for accessing service-meta-data from Java? I can’t find explicit documentation/examples on it.

I’d guess directly via MAAPI, rather than Navu?

2 Replies 2

previousqna
Level 8
Level 8

I suppose, the output of netconf-console would help:

netconf-console -u admin -p admin --get -x '/devices/device/config/interface'

The service-meta-data are shown with attributes backpointer and refcounter inside node’s tag (instance and ethernet below). Below is an example from what I see:

            <Port-channel>

              <name>1</name>

              <description>interface for testing</description>

              <service>

                <instance refcounter="1" backpointer="[ /ncs:services/siteswitch_multipoint_bridging:siteswitch_multipoint_bridging[siteswitch_multipoint_bridging:device='devIOS-0'][siteswitch_multipoint_bridging:interface-type='Port-channel'][siteswitch_multipoint_bridging:interface-index='1'][siteswitch_multipoint_bridging:vlan-id='103'] ]">

                  <id>3</id>

                  <ethernet refcounter="1" backpointer="[ /ncs:services/siteswitch_multipoint_bridging:siteswitch_multipoint_bridging[siteswitch_multipoint_bridging:device='devIOS-0'][siteswitch_multipoint_bridging:interface-type='Port-channel'][siteswitch_multipoint_bridging:interface-index='1'][siteswitch_multipoint_bridging:vlan-id='103'] ]"/>

Then, I need to parse in XML or Json to get the values in the tag. In Python, I was having difficulty to parse the attributes though as I observed default xml search did not work when I had attributes. If you remove tag attributes, then searching works well. But, then you will lose your service-meta-data.

So, I suggest you can play with regular expressions on the default xml output of the netconf. But, if you want to navigate, which I think you do need, then I am not sure what the efficient method is.

As far as I know, developers can get service-meta-data as same format as ncs_cli.

Code snippet:

---

try (MaapiInputStream mis = maapi.saveConfig(transactionId, EnumSet.of(MaapiConfigFlag.MAAPI_CONFIG_C, MaapiConfigFlag.MAAPI_CONFIG_WITH_SERVICE_META), serviceKeyPath);
      InputStreamReader ior = new InputStreamReader(mis);
      BufferedReader br = new BufferedReader(ior)) {
     br.lines().forEach(line -> LOGGER.debug(line));
} catch (Exception e) {

---

The point is MaapiConfigFlag.

MAAPI_CONFIG_WITH_SERVICE_META is what you wanted.

And, MAAPI_CONFIG_C is load as Cisco XR format. You can see also another format at MaapiConfigFlag.