2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.vtnrsc.cli.virtualport;
18 import java.util.Collection;
20 import org.apache.karaf.shell.commands.Command;
21 import org.apache.karaf.shell.commands.Option;
22 import org.onosproject.cli.AbstractShellCommand;
23 import org.onosproject.net.DeviceId;
24 import org.onosproject.vtnrsc.TenantNetworkId;
25 import org.onosproject.vtnrsc.VirtualPort;
26 import org.onosproject.vtnrsc.VirtualPortId;
27 import org.onosproject.vtnrsc.virtualport.VirtualPortService;
30 * Supports for querying virtualPorts.
32 @Command(scope = "onos", name = "virtualports", description = "Supports for querying virtualPorts.")
33 public class VirtualPortQueryCommand extends AbstractShellCommand {
35 @Option(name = "-v", aliases = "--vPortId", description = "virtualPort ID.", required = false,
39 @Option(name = "-n", aliases = "--networkId", description = "network ID.", required = false,
43 @Option(name = "-d", aliases = "--deviceId", description = "device ID.", required = false,
47 @Option(name = "-t", aliases = "--tenantId", description = "tenant ID.", required = false,
51 private static final String FMT = "virtualPortId=%s, networkId=%s, name=%s,"
52 + " tenantId=%s, deviceId=%s, adminStateUp=%s, state=%s,"
53 + " macAddress=%s, deviceOwner=%s, fixedIp=%s, bindingHostId=%s,"
54 + " bindingvnicType=%s, bindingvifType=%s, bindingvnicDetails=%s,"
55 + " allowedAddress=%s, securityGroups=%s";
58 protected void execute() {
59 VirtualPortService service = get(VirtualPortService.class);
60 if (vPortId != null && networkId == null && deviceId == null && tenantId == null) {
61 VirtualPort port = service.getPort(VirtualPortId.portId(vPortId));
63 } else if (vPortId == null && networkId != null && deviceId == null && tenantId == null) {
64 Collection<VirtualPort> ports = service.getPorts(TenantNetworkId.networkId(networkId));
66 } else if (vPortId == null && networkId == null && deviceId != null && tenantId == null) {
67 Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(deviceId));
69 } else if (vPortId == null && networkId == null && deviceId == null && tenantId != null) {
70 Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(tenantId));
72 } else if (vPortId == null && networkId == null && deviceId == null && tenantId == null) {
73 Collection<VirtualPort> ports = service.getPorts();
76 print("cannot input more than one parameter");
81 private void printPorts(Collection<VirtualPort> ports) {
82 for (VirtualPort port : ports) {
87 private void printPort(VirtualPort port) {
88 print(FMT, port.portId(), port.networkId(), port.name(), port.tenantId(), port.deviceId(),
89 port.adminStateUp(), port.state(), port.macAddress(), port.deviceOwner(), port
90 .fixedIps(), port.bindingHostId(), port.bindingVnicType(),
91 port.bindingVifType(), port.bindingVifDetails(), port.allowedAddressPairs(),
92 port.securityGroups());