blob: a6f304895e40fd8b9abc1df5aa79dcc690eda347 [file] [log] [blame]
tom13cb4852014-09-11 12:44:17 -07001package org.onlab.onos.cli.net;
2
3import com.google.common.collect.Lists;
4import org.apache.karaf.shell.commands.Argument;
5import org.apache.karaf.shell.commands.Command;
6import org.onlab.onos.net.DeviceId;
7import org.onlab.onos.net.topology.TopologyCluster;
8
9import java.util.Collections;
10import java.util.Comparator;
11import java.util.List;
12
13import 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")
20public class ClusterDevicesCommand extends ClustersListCommand {
21
22 @Argument(index = 0, name = "id", description = "Cluster ID",
23 required = false, multiValued = false)
24 String id = null;
25
26 protected static final Comparator<DeviceId> ID_COMPARATOR = new Comparator<DeviceId>() {
27 @Override
28 public int compare(DeviceId id1, DeviceId id2) {
29 return id1.uri().toString().compareTo(id2.uri().toString());
30 }
31 };
32
33 @Override
34 protected Object doExecute() throws Exception {
35 int cid = Integer.parseInt(id);
36 init();
37 TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
tom9eb57fb2014-09-11 19:42:38 -070038 if (cluster == null) {
39 error("No such cluster %s", cid);
40 } else {
41 List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster));
42 Collections.sort(ids, ID_COMPARATOR);
43 for (DeviceId deviceId : ids) {
44 print("%s", deviceId);
45 }
tom13cb4852014-09-11 12:44:17 -070046 }
tom9eb57fb2014-09-11 19:42:38 -070047
tom13cb4852014-09-11 12:44:17 -070048 return null;
49 }
50
51
52}