blob: 662798e734910c604cec4354203a0844aaafe002 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom13cb4852014-09-11 12:44:17 -070019package org.onlab.onos.cli.net;
20
21import org.apache.karaf.shell.commands.Argument;
22import org.apache.karaf.shell.commands.Command;
23import org.onlab.onos.net.Link;
24import org.onlab.onos.net.topology.TopologyCluster;
25
tom32085cf2014-10-16 00:04:33 -070026import static org.onlab.onos.cli.net.LinksListCommand.json;
tom13cb4852014-09-11 12:44:17 -070027import static org.onlab.onos.cli.net.LinksListCommand.linkString;
28import static org.onlab.onos.net.topology.ClusterId.clusterId;
29
30/**
31 * Lists links of the specified topology cluster in the current topology.
32 */
33@Command(scope = "onos", name = "cluster-links",
34 description = "Lists links of the specified topology cluster in the current topology")
35public class ClusterLinksCommand extends ClustersListCommand {
36
37 @Argument(index = 0, name = "id", description = "Cluster ID",
tom613d8142014-09-11 15:09:37 -070038 required = true, multiValued = false)
tom13cb4852014-09-11 12:44:17 -070039 String id = null;
40
41 @Override
tom0872a172014-09-23 11:24:26 -070042 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070043 int cid = Integer.parseInt(id);
44 init();
45 TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
tom9eb57fb2014-09-11 19:42:38 -070046 if (cluster == null) {
47 error("No such cluster %s", cid);
tom32085cf2014-10-16 00:04:33 -070048 } else if (outputJson()) {
49 print("%s", json(service.getClusterLinks(topology, cluster)));
tom9eb57fb2014-09-11 19:42:38 -070050 } else {
51 for (Link link : service.getClusterLinks(topology, cluster)) {
52 print(linkString(link));
53 }
tom13cb4852014-09-11 12:44:17 -070054 }
tom13cb4852014-09-11 12:44:17 -070055 }
56
tom13cb4852014-09-11 12:44:17 -070057}