Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [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 | |
| 17 | package org.onosproject.openstacknode.cli; |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.Port; |
| 24 | import org.onosproject.net.Device; |
| 25 | import org.onosproject.net.device.DeviceService; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 26 | import org.onosproject.openstacknode.api.OpenstackNode; |
| 27 | import org.onosproject.openstacknode.api.OpenstackNodeService; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 28 | |
| 29 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
Jian Li | 5afbea4 | 2018-02-28 10:37:03 +0900 | [diff] [blame] | 30 | import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL; |
| 31 | import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Checks detailed node init state. |
| 35 | */ |
| 36 | @Command(scope = "onos", name = "openstack-node-check", |
| 37 | description = "Shows detailed node init state") |
| 38 | public class OpenstackNodeCheckCommand extends AbstractShellCommand { |
| 39 | |
| 40 | @Argument(index = 0, name = "hostname", description = "Hostname", |
| 41 | required = true, multiValued = false) |
| 42 | private String hostname = null; |
| 43 | |
| 44 | private static final String MSG_OK = "OK"; |
| 45 | private static final String MSG_NO = "NO"; |
| 46 | |
| 47 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 48 | protected void doExecute() { |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 49 | OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 50 | DeviceService deviceService = AbstractShellCommand.get(DeviceService.class); |
| 51 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 52 | OpenstackNode osNode = osNodeService.node(hostname); |
| 53 | if (osNode == null) { |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 54 | print("Cannot find %s from registered nodes", hostname); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 55 | return; |
| 56 | } |
| 57 | |
Hyunsun Moon | 052c71f | 2016-07-11 18:56:18 -0700 | [diff] [blame] | 58 | print("[Integration Bridge Status]"); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 59 | Device device = deviceService.getDevice(osNode.intgBridge()); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 60 | if (device != null) { |
| 61 | print("%s %s=%s available=%s %s", |
| 62 | deviceService.isAvailable(device.id()) ? MSG_OK : MSG_NO, |
| 63 | INTEGRATION_BRIDGE, |
| 64 | device.id(), |
| 65 | deviceService.isAvailable(device.id()), |
| 66 | device.annotations()); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 67 | if (osNode.dataIp() != null) { |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 68 | printPortState(deviceService, osNode.intgBridge(), DEFAULT_TUNNEL); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 69 | } |
| 70 | if (osNode.vlanIntf() != null) { |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 71 | printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf()); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 72 | } |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 73 | if (osNode.type() == OpenstackNode.NodeType.GATEWAY) { |
| 74 | printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort()); |
| 75 | } |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 76 | } else { |
| 77 | print("%s %s=%s is not available", |
| 78 | MSG_NO, |
| 79 | INTEGRATION_BRIDGE, |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 80 | osNode.intgBridge()); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 81 | } |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 84 | private void printPortState(DeviceService deviceService, DeviceId deviceId, String portName) { |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 85 | Port port = deviceService.getPorts(deviceId).stream() |
| 86 | .filter(p -> p.annotations().value(PORT_NAME).equals(portName) && |
| 87 | p.isEnabled()) |
| 88 | .findAny().orElse(null); |
| 89 | |
| 90 | if (port != null) { |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 91 | print("%s %s portNum=%s enabled=%s %s", |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 92 | port.isEnabled() ? MSG_OK : MSG_NO, |
| 93 | portName, |
| 94 | port.number(), |
| 95 | port.isEnabled() ? Boolean.TRUE : Boolean.FALSE, |
| 96 | port.annotations()); |
| 97 | } else { |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 98 | print("%s %s does not exist", MSG_NO, portName); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 99 | } |
| 100 | } |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 101 | } |