jiangrui | 8143ad4 | 2015-08-12 15:26:20 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
jiangrui | 8143ad4 | 2015-08-12 15:26:20 +0800 | [diff] [blame] | 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.virtualport; |
| 17 | |
| 18 | import java.util.Collection; |
| 19 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Command; |
| 21 | import org.apache.karaf.shell.api.action.Option; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
jiangrui | 8143ad4 | 2015-08-12 15:26:20 +0800 | [diff] [blame] | 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 26 | import org.onosproject.vtnrsc.VirtualPort; |
| 27 | import org.onosproject.vtnrsc.VirtualPortId; |
| 28 | import org.onosproject.vtnrsc.virtualport.VirtualPortService; |
| 29 | |
| 30 | /** |
| 31 | * Supports for querying virtualPorts. |
| 32 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 33 | @Service |
jiangrui | 8143ad4 | 2015-08-12 15:26:20 +0800 | [diff] [blame] | 34 | @Command(scope = "onos", name = "virtualports", description = "Supports for querying virtualPorts.") |
| 35 | public class VirtualPortQueryCommand extends AbstractShellCommand { |
| 36 | |
| 37 | @Option(name = "-v", aliases = "--vPortId", description = "virtualPort ID.", required = false, |
| 38 | multiValued = false) |
| 39 | String vPortId; |
| 40 | |
| 41 | @Option(name = "-n", aliases = "--networkId", description = "network ID.", required = false, |
| 42 | multiValued = false) |
| 43 | String networkId; |
| 44 | |
| 45 | @Option(name = "-d", aliases = "--deviceId", description = "device ID.", required = false, |
| 46 | multiValued = false) |
| 47 | String deviceId; |
| 48 | |
| 49 | @Option(name = "-t", aliases = "--tenantId", description = "tenant ID.", required = false, |
| 50 | multiValued = false) |
| 51 | String tenantId; |
| 52 | |
| 53 | private static final String FMT = "virtualPortId=%s, networkId=%s, name=%s," |
| 54 | + " tenantId=%s, deviceId=%s, adminStateUp=%s, state=%s," |
| 55 | + " macAddress=%s, deviceOwner=%s, fixedIp=%s, bindingHostId=%s," |
| 56 | + " bindingvnicType=%s, bindingvifType=%s, bindingvnicDetails=%s," |
| 57 | + " allowedAddress=%s, securityGroups=%s"; |
| 58 | |
| 59 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 60 | protected void doExecute() { |
jiangrui | 8143ad4 | 2015-08-12 15:26:20 +0800 | [diff] [blame] | 61 | VirtualPortService service = get(VirtualPortService.class); |
| 62 | if (vPortId != null && networkId == null && deviceId == null && tenantId == null) { |
| 63 | VirtualPort port = service.getPort(VirtualPortId.portId(vPortId)); |
| 64 | printPort(port); |
| 65 | } else if (vPortId == null && networkId != null && deviceId == null && tenantId == null) { |
| 66 | Collection<VirtualPort> ports = service.getPorts(TenantNetworkId.networkId(networkId)); |
| 67 | printPorts(ports); |
| 68 | } else if (vPortId == null && networkId == null && deviceId != null && tenantId == null) { |
| 69 | Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(deviceId)); |
| 70 | printPorts(ports); |
| 71 | } else if (vPortId == null && networkId == null && deviceId == null && tenantId != null) { |
| 72 | Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(tenantId)); |
| 73 | printPorts(ports); |
| 74 | } else if (vPortId == null && networkId == null && deviceId == null && tenantId == null) { |
| 75 | Collection<VirtualPort> ports = service.getPorts(); |
| 76 | printPorts(ports); |
| 77 | } else { |
| 78 | print("cannot input more than one parameter"); |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | private void printPorts(Collection<VirtualPort> ports) { |
| 84 | for (VirtualPort port : ports) { |
| 85 | printPort(port); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | private void printPort(VirtualPort port) { |
| 90 | print(FMT, port.portId(), port.networkId(), port.name(), port.tenantId(), port.deviceId(), |
| 91 | port.adminStateUp(), port.state(), port.macAddress(), port.deviceOwner(), port |
| 92 | .fixedIps(), port.bindingHostId(), port.bindingVnicType(), |
| 93 | port.bindingVifType(), port.bindingVifDetails(), port.allowedAddressPairs(), |
| 94 | port.securityGroups()); |
| 95 | } |
| 96 | } |