blob: 9c68244e32f091562e3288182fe03e6137b0a012 [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;
tom13cb4852014-09-11 12:44:17 -070010import java.util.List;
11
12import static org.onlab.onos.net.topology.ClusterId.clusterId;
13
14/**
15 * Lists devices of the specified topology cluster in the current topology.
16 */
17@Command(scope = "onos", name = "cluster-devices",
18 description = "Lists devices of the specified topology cluster in the current topology")
19public class ClusterDevicesCommand extends ClustersListCommand {
20
21 @Argument(index = 0, name = "id", description = "Cluster ID",
22 required = false, multiValued = false)
23 String id = null;
24
tom13cb4852014-09-11 12:44:17 -070025 @Override
tom0872a172014-09-23 11:24:26 -070026 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070027 int cid = Integer.parseInt(id);
28 init();
29 TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
tom9eb57fb2014-09-11 19:42:38 -070030 if (cluster == null) {
31 error("No such cluster %s", cid);
32 } else {
33 List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster));
tom1380eee2014-09-24 09:22:02 -070034 Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR);
tom9eb57fb2014-09-11 19:42:38 -070035 for (DeviceId deviceId : ids) {
36 print("%s", deviceId);
37 }
tom13cb4852014-09-11 12:44:17 -070038 }
tom13cb4852014-09-11 12:44:17 -070039 }
40
41
42}