blob: 6a20fd3526c56b3e50ef8a4526d520ae7c285f13 [file] [log] [blame]
jiangrui7d2d7fb2015-08-11 18:43:57 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui7d2d7fb2015-08-11 18:43:57 +08003 *
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 */
16package org.onosproject.vtnrsc.cli.network;
17
18import org.apache.karaf.shell.commands.Command;
19import org.apache.karaf.shell.commands.Option;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.vtnrsc.TenantNetwork;
22import org.onosproject.vtnrsc.TenantNetworkId;
23import 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")
30public 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}