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