cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1828
Views
0
Helpful
10
Replies

Sync-from selected devices

Shashank Srivastava
Cisco Employee
Cisco Employee

Hi,

 

I am trying to sync-from only a certain numbers of devices using java api Maapi.requestAction(new ConfXMLParam[] {},"/ncs:devices/sync-from/device%s" ," [ ios aris0 ]") method but it throws an exception that not a valid action which is correct as from maapi.requestAction docs its clear that last element in xpath should be an action. Simplest way is to run /ncs:devices/device{%s}/sync-from in loop.

 

This works fine on cli though:

admin@ncs-rfs-1# devices sync-from device [ ios aris0 ]

sync-result {
device aris0
result true
}
sync-result {
device ios
result true
}

 

Is there any other way to run this command and get the result of the commands.

 

Thanks,

Shashank

1 Accepted Solution

Accepted Solutions

Hi Shashank,

If you are still looking for how to do this, you can do:

        ConfNamespace ncs = new Ncs();
        ConfList devices_to_sync = new ConfList();
        devices_to_sync.addElem(new ConfBuf("ios"));
        devices_to_sync.addElem(new ConfBuf("aris0"));
        ConfXMLParam[] params = new ConfXMLParam[] {
            new ConfXMLParamValue(ncs, "device", devices_to_sync)
        };

        ConfXMLParam[] res =
            maapi.requestAction(params, "/ncs:devices/sync-from");

You have to pass a leaf-list of device names as the input parameter to the action.

/Ram

View solution in original post

10 Replies 10

yfherzog
Cisco Employee
Cisco Employee

Check the Java API documentation for the method usage:

<install-dir>/doc/api/java/com/tailf/maapi/Maapi.html

 

As far as I understand it, your first parameter will either be ConfXMLParam in one form or the other (list, array) and the second one will be the path to the action.

That's right, I missed it while writing this post. Edited the same. Thanks for pointing.

The first argument should be your parameters, rather than third.

 

public ConfXMLParam[] requestAction(ConfXMLParam[] params,
String fmt,
Object... arguments)
throws IOException,
ConfException
Invokes an action defined in the data model annotated with tailf:action (see tailf_yang_extensions(5)).
The input parameters is specified as ConfXMLParam as the input array param which corresponds to the input section of the action.

The output parameters returned from the method call returns a array of ConfXMLParam which corresponds to the output section of the action.

 

The path given by fmt and the varargs list is the full path to the action, i.e. the final element must be the name of the action element in the YANG model.

Since actions are not associated with transactions, the namespace must be provided and the path must be absolute transactions, the namespace must be provided and the path must be absolute - but see requestActionTh(int,ConfXMLParam[],String,Object...).

The Maapi instance must have an established user session before issue this method call.

Parameters:
params - action input parameters
fmt - path string, this must be an absolute path with its root element prefixed .i.e "/prefix:tagname/...."
arguments - optional parameters for substitution in fmt
Returns:
array of ConfXMLParam as the output parameters

The third parameter is string representation of list of devices to simulate cli command:
devices sync-from devices [ ios aris0 ]

fmt - path string, this must be an absolute path with its root element prefixed .i.e "/prefix:tagname/...."
arguments - optional parameters for substitution in fmt

 

The third parameter is for substitution in the second parameter which is the path.

The list of devices is not a part of the path to the action but a part of the inputs.

You need them on the first parameter formatted as ConfXMLParam.

Look for instance at examples.ncs/getting-started/developing-with-ncs/2-actions/packages/actions/src/java/test/com/example/actions/Sync.java for an example of how to format the input parameters, hopefully that helps you a bit.

vleijon
Cisco Employee
Cisco Employee

Have you tried looking in the examples, there are a few examples of how to format the parameters.

 

Anyhow, a leaf-list cannot be encoded in a string like that. Try maybe an array? (I can't remember the java representation off of the top of my head.)

I am at present going through java doc but till now didn't find anything that could serve my purpose.

Hi Shashank,

If you are still looking for how to do this, you can do:

        ConfNamespace ncs = new Ncs();
        ConfList devices_to_sync = new ConfList();
        devices_to_sync.addElem(new ConfBuf("ios"));
        devices_to_sync.addElem(new ConfBuf("aris0"));
        ConfXMLParam[] params = new ConfXMLParam[] {
            new ConfXMLParamValue(ncs, "device", devices_to_sync)
        };

        ConfXMLParam[] res =
            maapi.requestAction(params, "/ncs:devices/sync-from");

You have to pass a leaf-list of device names as the input parameter to the action.

/Ram

Works like a charm.. I am now able to understand what Yftach and Viktor were pointing. This example is straight forward and has helped in achieving what I wanted to. Thanks Ram for solution!!
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community:

Recognize Your Peers