Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.Link; |
| 23 | import org.onosproject.net.topology.TopologyCluster; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 24 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import static org.onosproject.cli.net.LinksListCommand.json; |
| 26 | import static org.onosproject.cli.net.LinksListCommand.linkString; |
| 27 | import static org.onosproject.net.topology.ClusterId.clusterId; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Lists links of the specified topology cluster in the current topology. |
| 31 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 32 | @Service |
Charles Chan | 3da0b1d | 2018-04-17 20:25:32 -0700 | [diff] [blame] | 33 | @Command(scope = "onos", name = "topo-cluster-links", |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 34 | description = "Lists links of the specified topology cluster in the current topology") |
| 35 | public class ClusterLinksCommand extends ClustersListCommand { |
| 36 | |
| 37 | @Argument(index = 0, name = "id", description = "Cluster ID", |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 38 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 39 | @Completion(ClusterIdCompleter.class) |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 40 | String id = null; |
| 41 | |
| 42 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 43 | protected void doExecute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 44 | int cid = Integer.parseInt(id); |
| 45 | init(); |
| 46 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 47 | if (cluster == null) { |
| 48 | error("No such cluster %s", cid); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 49 | } else if (outputJson()) { |
Ray Milkey | 3078fc0 | 2015-05-06 16:14:14 -0700 | [diff] [blame] | 50 | print("%s", json(this, service.getClusterLinks(topology, cluster))); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 51 | } else { |
| 52 | for (Link link : service.getClusterLinks(topology, cluster)) { |
| 53 | print(linkString(link)); |
| 54 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 55 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 56 | } |
| 57 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 58 | } |