blob: 4528008f3f11f550b4f30b4e3cd3ea69dd755da1 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
tom13cb4852014-09-11 12:44:17 -070017
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.Link;
21import org.onosproject.net.topology.TopologyCluster;
tom13cb4852014-09-11 12:44:17 -070022
Brian O'Connorabafb502014-12-02 22:26:20 -080023import static org.onosproject.cli.net.LinksListCommand.json;
24import static org.onosproject.cli.net.LinksListCommand.linkString;
25import static org.onosproject.net.topology.ClusterId.clusterId;
tom13cb4852014-09-11 12:44:17 -070026
27/**
28 * Lists links of the specified topology cluster in the current topology.
29 */
30@Command(scope = "onos", name = "cluster-links",
31 description = "Lists links of the specified topology cluster in the current topology")
32public class ClusterLinksCommand extends ClustersListCommand {
33
34 @Argument(index = 0, name = "id", description = "Cluster ID",
tom613d8142014-09-11 15:09:37 -070035 required = true, multiValued = false)
tom13cb4852014-09-11 12:44:17 -070036 String id = null;
37
38 @Override
tom0872a172014-09-23 11:24:26 -070039 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070040 int cid = Integer.parseInt(id);
41 init();
42 TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
tom9eb57fb2014-09-11 19:42:38 -070043 if (cluster == null) {
44 error("No such cluster %s", cid);
tom32085cf2014-10-16 00:04:33 -070045 } else if (outputJson()) {
Ray Milkey3078fc02015-05-06 16:14:14 -070046 print("%s", json(this, service.getClusterLinks(topology, cluster)));
tom9eb57fb2014-09-11 19:42:38 -070047 } else {
48 for (Link link : service.getClusterLinks(topology, cluster)) {
49 print(linkString(link));
50 }
tom13cb4852014-09-11 12:44:17 -070051 }
tom13cb4852014-09-11 12:44:17 -070052 }
53
tom13cb4852014-09-11 12:44:17 -070054}