tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 4 | import com.google.common.collect.Lists; |
| 5 | import org.apache.karaf.shell.commands.Argument; |
| 6 | import org.apache.karaf.shell.commands.Command; |
tom | 91c7bd0 | 2014-09-25 22:50:44 -0700 | [diff] [blame] | 7 | import org.onlab.onos.cli.Comparators; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.DeviceId; |
| 9 | import org.onlab.onos.net.topology.TopologyCluster; |
| 10 | |
| 11 | import java.util.Collections; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 12 | import java.util.List; |
| 13 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 14 | import static org.onlab.onos.cli.MastersListCommand.json; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 15 | import static org.onlab.onos.net.topology.ClusterId.clusterId; |
| 16 | |
| 17 | /** |
| 18 | * Lists devices of the specified topology cluster in the current topology. |
| 19 | */ |
| 20 | @Command(scope = "onos", name = "cluster-devices", |
| 21 | description = "Lists devices of the specified topology cluster in the current topology") |
| 22 | public class ClusterDevicesCommand extends ClustersListCommand { |
| 23 | |
| 24 | @Argument(index = 0, name = "id", description = "Cluster ID", |
| 25 | required = false, multiValued = false) |
| 26 | String id = null; |
| 27 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 28 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 29 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 30 | int cid = Integer.parseInt(id); |
| 31 | init(); |
| 32 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 33 | if (cluster == null) { |
| 34 | error("No such cluster %s", cid); |
| 35 | } else { |
| 36 | List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster)); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 37 | Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 38 | if (outputJson()) { |
| 39 | print("%s", json(new ObjectMapper(), ids)); |
| 40 | } else { |
| 41 | for (DeviceId deviceId : ids) { |
| 42 | print("%s", deviceId); |
| 43 | } |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 44 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 45 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 46 | } |
| 47 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 48 | } |