jiangrui | 7d2d7fb | 2015-08-11 18:43:57 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | package org.onosproject.vtnrsc.cli.network; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Command; |
| 19 | import org.apache.karaf.shell.commands.Option; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.vtnrsc.TenantNetwork; |
| 22 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 23 | import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; |
| 24 | |
| 25 | /** |
| 26 | * Supports for querying TenantNetworks by network id. |
| 27 | */ |
| 28 | @Command(scope = "onos", name = "tenantnetworks", description = "Supports for querying" |
| 29 | + "tenantNetworks by networkid") |
| 30 | public class TenantNetworkQueryCommand extends AbstractShellCommand { |
| 31 | |
| 32 | @Option(name = "-i", aliases = "--id", description = "TenantNetwork id", required = false, |
| 33 | multiValued = false) |
| 34 | String id = null; |
| 35 | |
| 36 | private static final String FMT = "networkId=%s, networkName=%s, segmentationId=%s," |
| 37 | + "tenantId=%s, type=%s, adminStateUp=%s"; |
| 38 | |
| 39 | @Override |
| 40 | protected void execute() { |
| 41 | TenantNetworkService service = get(TenantNetworkService.class); |
| 42 | if (id != null) { |
| 43 | TenantNetwork network = service.getNetwork(TenantNetworkId.networkId(id)); |
| 44 | printNetwork(network); |
| 45 | } else { |
| 46 | Iterable<TenantNetwork> networks = service.getNetworks(); |
| 47 | for (TenantNetwork network : networks) { |
| 48 | printNetwork(network); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | private void printNetwork(TenantNetwork network) { |
| 54 | if (network == null) { |
| 55 | return; |
| 56 | } |
| 57 | print(FMT, network.id(), network.name(), network.segmentationId(), |
| 58 | network.tenantId(), network.type(), network.adminStateUp()); |
| 59 | } |
| 60 | } |