tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onlab.onos.net.Link; |
| 6 | import org.onlab.onos.net.topology.TopologyCluster; |
| 7 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 8 | import static org.onlab.onos.cli.net.LinksListCommand.json; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 9 | import static org.onlab.onos.cli.net.LinksListCommand.linkString; |
| 10 | import 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") |
| 17 | public class ClusterLinksCommand extends ClustersListCommand { |
| 18 | |
| 19 | @Argument(index = 0, name = "id", description = "Cluster ID", |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 20 | required = true, multiValued = false) |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 21 | String id = null; |
| 22 | |
| 23 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 24 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 25 | int cid = Integer.parseInt(id); |
| 26 | init(); |
| 27 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 28 | if (cluster == null) { |
| 29 | error("No such cluster %s", cid); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 30 | } else if (outputJson()) { |
| 31 | print("%s", json(service.getClusterLinks(topology, cluster))); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 32 | } else { |
| 33 | for (Link link : service.getClusterLinks(topology, cluster)) { |
| 34 | print(linkString(link)); |
| 35 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 36 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 37 | } |
| 38 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 39 | } |