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; |
| 6 | import org.onlab.onos.net.DeviceId; |
| 7 | import org.onlab.onos.net.topology.TopologyCluster; |
| 8 | |
| 9 | import java.util.Collections; |
| 10 | import java.util.Comparator; |
| 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 | |
| 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)); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 38 | 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 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 46 | } |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 47 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 48 | return null; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | } |