blob: f09b1852740fa0e528853f5e41340c3c727e9f48 [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;
tom91c7bd02014-09-25 22:50:44 -07006import org.onlab.onos.cli.Comparators;
tom13cb4852014-09-11 12:44:17 -07007import org.onlab.onos.net.DeviceId;
8import org.onlab.onos.net.topology.TopologyCluster;
9
10import java.util.Collections;
tom13cb4852014-09-11 12:44:17 -070011import 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
tom13cb4852014-09-11 12:44:17 -070026 @Override
tom0872a172014-09-23 11:24:26 -070027 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070028 int cid = Integer.parseInt(id);
29 init();
30 TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
tom9eb57fb2014-09-11 19:42:38 -070031 if (cluster == null) {
32 error("No such cluster %s", cid);
33 } else {
34 List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster));
tom1380eee2014-09-24 09:22:02 -070035 Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR);
tom9eb57fb2014-09-11 19:42:38 -070036 for (DeviceId deviceId : ids) {
37 print("%s", deviceId);
38 }
tom13cb4852014-09-11 12:44:17 -070039 }
tom13cb4852014-09-11 12:44:17 -070040 }
41
42
43}