blob: ed5be778b8591d17becdc7f33e6904dc9be601cb [file] [log] [blame]
tom13cb4852014-09-11 12:44:17 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.commands.Argument;
4import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.net.Link;
6import org.onlab.onos.net.topology.TopologyCluster;
7
tom32085cf2014-10-16 00:04:33 -07008import static org.onlab.onos.cli.net.LinksListCommand.json;
tom13cb4852014-09-11 12:44:17 -07009import static org.onlab.onos.cli.net.LinksListCommand.linkString;
10import static org.onlab.onos.net.topology.ClusterId.clusterId;
11
12/**
13 * Lists links of the specified topology cluster in the current topology.
14 */
15@Command(scope = "onos", name = "cluster-links",
16 description = "Lists links of the specified topology cluster in the current topology")
17public class ClusterLinksCommand extends ClustersListCommand {
18
19 @Argument(index = 0, name = "id", description = "Cluster ID",
tom613d8142014-09-11 15:09:37 -070020 required = true, multiValued = false)
tom13cb4852014-09-11 12:44:17 -070021 String id = null;
22
23 @Override
tom0872a172014-09-23 11:24:26 -070024 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070025 int cid = Integer.parseInt(id);
26 init();
27 TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
tom9eb57fb2014-09-11 19:42:38 -070028 if (cluster == null) {
29 error("No such cluster %s", cid);
tom32085cf2014-10-16 00:04:33 -070030 } else if (outputJson()) {
31 print("%s", json(service.getClusterLinks(topology, cluster)));
tom9eb57fb2014-09-11 19:42:38 -070032 } else {
33 for (Link link : service.getClusterLinks(topology, cluster)) {
34 print(linkString(link));
35 }
tom13cb4852014-09-11 12:44:17 -070036 }
tom13cb4852014-09-11 12:44:17 -070037 }
38
tom13cb4852014-09-11 12:44:17 -070039}