02-20-2019 11:42 PM - edited 02-21-2019 12:28 AM
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
Solved! Go to Solution.
02-22-2019 01:44 AM
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
02-21-2019 12:23 AM
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.
02-21-2019 12:27 AM
That's right, I missed it while writing this post. Edited the same. Thanks for pointing.
02-21-2019 12:37 AM
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
02-21-2019 12:47 AM
02-21-2019 12:50 AM
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.
02-21-2019 12:50 AM
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.
02-21-2019 12:36 AM
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.)
02-21-2019 12:38 AM
02-22-2019 01:44 AM
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
02-22-2019 03:04 AM
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