Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.Link; |
| 21 | import org.onosproject.net.topology.TopologyCluster; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 22 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import static org.onosproject.cli.net.LinksListCommand.json; |
| 24 | import static org.onosproject.cli.net.LinksListCommand.linkString; |
| 25 | import static org.onosproject.net.topology.ClusterId.clusterId; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 26 | |
| 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") |
| 32 | public class ClusterLinksCommand extends ClustersListCommand { |
| 33 | |
| 34 | @Argument(index = 0, name = "id", description = "Cluster ID", |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 35 | required = true, multiValued = false) |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 36 | String id = null; |
| 37 | |
| 38 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 39 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 40 | int cid = Integer.parseInt(id); |
| 41 | init(); |
| 42 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 43 | if (cluster == null) { |
| 44 | error("No such cluster %s", cid); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 45 | } else if (outputJson()) { |
Ray Milkey | 3078fc0 | 2015-05-06 16:14:14 -0700 | [diff] [blame] | 46 | print("%s", json(this, service.getClusterLinks(topology, cluster))); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 47 | } else { |
| 48 | for (Link link : service.getClusterLinks(topology, cluster)) { |
| 49 | print(linkString(link)); |
| 50 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 51 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 52 | } |
| 53 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 54 | } |