blob: d4d6d24551865fe2e567d50dae60bb308ea2ce8e [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));
38 List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster));
39 Collections.sort(ids, ID_COMPARATOR);
40 for (DeviceId deviceId : ids) {
41 print("%s", deviceId);
42 }
43 return null;
44 }
45
46
47}