mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-11-03 01:31:21 +01:00
Enahnced path list command to show JSON.
This commit is contained in:
parent
8350ba5108
commit
c65fa11ca2
@ -66,7 +66,7 @@ public class LinksListCommand extends AbstractShellCommand {
|
||||
public static ObjectNode json(ObjectMapper mapper, Link link) {
|
||||
ObjectNode result = mapper.createObjectNode();
|
||||
result.set("src", json(mapper, link.src()));
|
||||
result.set("dst", json(mapper, link.src()));
|
||||
result.set("dst", json(mapper, link.dst()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package org.onlab.onos.cli.net;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.apache.karaf.shell.commands.Argument;
|
||||
import org.apache.karaf.shell.commands.Command;
|
||||
import org.onlab.onos.net.Link;
|
||||
@ -32,11 +35,32 @@ public class PathListCommand extends TopologyCommand {
|
||||
protected void execute() {
|
||||
init();
|
||||
Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst));
|
||||
for (Path path : paths) {
|
||||
print(pathString(path));
|
||||
if (outputJson()) {
|
||||
print("%s", json(paths));
|
||||
} else {
|
||||
for (Path path : paths) {
|
||||
print(pathString(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a JSON array containing the specified paths.
|
||||
*
|
||||
* @param paths collection of paths
|
||||
* @return JSON array
|
||||
*/
|
||||
public static JsonNode json(Iterable<Path> paths) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ArrayNode result = mapper.createArrayNode();
|
||||
for (Path path : paths) {
|
||||
result.add(LinksListCommand.json(mapper, path)
|
||||
.put("cost", path.cost())
|
||||
.set("links", LinksListCommand.json(path.links())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a formatted string representing the specified path.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user