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; |
Jian Li | db521c1 | 2018-11-19 17:42:35 +0900 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 23 | import org.onosproject.cli.AbstractShellCommand; |
Jian Li | 5ecfd1a | 2018-12-10 11:41:03 +0900 | [diff] [blame] | 24 | import org.onosproject.net.Device; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.Port; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 27 | import org.onosproject.net.device.DeviceService; |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 28 | import org.onosproject.openstacknode.api.NodeState; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 29 | import org.onosproject.openstacknode.api.OpenstackNode; |
| 30 | import org.onosproject.openstacknode.api.OpenstackNodeService; |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 31 | import org.openstack4j.api.OSClient; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 32 | |
| 33 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
Jian Li | 2d68c19 | 2018-12-13 15:52:59 +0900 | [diff] [blame] | 34 | import static org.onosproject.openstacknode.api.Constants.GRE_TUNNEL; |
| 35 | import static org.onosproject.openstacknode.api.Constants.VXLAN_TUNNEL; |
Jian Li | 5afbea4 | 2018-02-28 10:37:03 +0900 | [diff] [blame] | 36 | import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE; |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 37 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER; |
| 38 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY; |
| 39 | import static org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Checks detailed node init state. |
| 43 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 44 | @Service |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 45 | @Command(scope = "onos", name = "openstack-node-check", |
| 46 | description = "Shows detailed node init state") |
| 47 | public class OpenstackNodeCheckCommand extends AbstractShellCommand { |
| 48 | |
| 49 | @Argument(index = 0, name = "hostname", description = "Hostname", |
| 50 | required = true, multiValued = false) |
Jian Li | db521c1 | 2018-11-19 17:42:35 +0900 | [diff] [blame] | 51 | @Completion(OpenstackHostnameCompleter.class) |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 52 | private String hostname = null; |
| 53 | |
| 54 | private static final String MSG_OK = "OK"; |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 55 | private static final String MSG_ERROR = "ERROR"; |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 56 | |
| 57 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 58 | protected void doExecute() { |
Jian Li | 5ecfd1a | 2018-12-10 11:41:03 +0900 | [diff] [blame] | 59 | OpenstackNodeService osNodeService = get(OpenstackNodeService.class); |
| 60 | DeviceService deviceService = get(DeviceService.class); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 61 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 62 | OpenstackNode osNode = osNodeService.node(hostname); |
| 63 | if (osNode == null) { |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 64 | print("Cannot find %s from registered nodes", hostname); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 68 | if (osNode.type() == CONTROLLER) { |
| 69 | print("[Openstack Controller Status]"); |
| 70 | |
| 71 | OSClient client = getConnectedClient(osNode); |
| 72 | if (client == null) { |
| 73 | error("The given keystone info is incorrect to get authorized to openstack"); |
| 74 | print("keystoneConfig=%s", osNode.keystoneConfig()); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 75 | } |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 76 | |
| 77 | if (osNode.keystoneConfig() != null) { |
| 78 | print("%s keystoneConfig=%s, neutronConfig=%s", |
| 79 | osNode.state() == NodeState.COMPLETE && client != null ? |
| 80 | MSG_OK : MSG_ERROR, |
| 81 | osNode.keystoneConfig(), |
| 82 | osNode.neutronConfig()); |
| 83 | } else { |
| 84 | print("%s keystoneConfig is missing", MSG_ERROR); |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 85 | } |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 86 | } else { |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 87 | print("[Integration Bridge Status]"); |
| 88 | Device device = deviceService.getDevice(osNode.intgBridge()); |
Daniel Park | 0ba22e4 | 2019-04-11 18:22:50 +0900 | [diff] [blame] | 89 | Device ovsdbDevice = deviceService.getDevice(osNode.ovsdb()); |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 90 | if (device != null) { |
Daniel Park | 0ba22e4 | 2019-04-11 18:22:50 +0900 | [diff] [blame] | 91 | print("%s OvsdbDeviceId=%s available=%s", |
| 92 | deviceService.isAvailable(ovsdbDevice.id()) ? MSG_OK : MSG_ERROR, |
| 93 | ovsdbDevice.id(), |
| 94 | deviceService.isAvailable(ovsdbDevice.id())); |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 95 | print("%s %s=%s available=%s %s", |
| 96 | deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR, |
| 97 | INTEGRATION_BRIDGE, |
| 98 | device.id(), |
| 99 | deviceService.isAvailable(device.id()), |
| 100 | device.annotations()); |
| 101 | if (osNode.dataIp() != null) { |
Jian Li | 2d68c19 | 2018-12-13 15:52:59 +0900 | [diff] [blame] | 102 | printPortState(deviceService, osNode.intgBridge(), VXLAN_TUNNEL); |
| 103 | printPortState(deviceService, osNode.intgBridge(), GRE_TUNNEL); |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 104 | } |
| 105 | if (osNode.vlanIntf() != null) { |
| 106 | printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf()); |
| 107 | } |
Daniel Park | d45f004 | 2019-03-27 14:48:33 +0900 | [diff] [blame] | 108 | osNode.phyIntfs().forEach(intf -> { |
| 109 | printPortState(deviceService, osNode.intgBridge(), intf.intf()); |
| 110 | }); |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 111 | if (osNode.type() == GATEWAY) { |
| 112 | printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort()); |
| 113 | } |
| 114 | } else { |
| 115 | print("%s %s=%s is not available", |
| 116 | MSG_ERROR, |
| 117 | INTEGRATION_BRIDGE, |
| 118 | osNode.intgBridge()); |
| 119 | } |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 120 | } |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Jian Li | 5ecfd1a | 2018-12-10 11:41:03 +0900 | [diff] [blame] | 123 | private void printPortState(DeviceService deviceService, |
| 124 | DeviceId deviceId, String portName) { |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 125 | Port port = deviceService.getPorts(deviceId).stream() |
| 126 | .filter(p -> p.annotations().value(PORT_NAME).equals(portName) && |
| 127 | p.isEnabled()) |
| 128 | .findAny().orElse(null); |
| 129 | |
| 130 | if (port != null) { |
Hyunsun Moon | a946564 | 2017-06-29 16:28:58 +0900 | [diff] [blame] | 131 | print("%s %s portNum=%s enabled=%s %s", |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 132 | port.isEnabled() ? MSG_OK : MSG_ERROR, |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 133 | portName, |
| 134 | port.number(), |
| 135 | port.isEnabled() ? Boolean.TRUE : Boolean.FALSE, |
| 136 | port.annotations()); |
| 137 | } else { |
Jian Li | a09f3c3 | 2018-10-08 10:48:34 +0900 | [diff] [blame] | 138 | print("%s %s does not exist", MSG_ERROR, portName); |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
Hyunsun Moon | 34bbe17 | 2016-06-28 19:18:40 -0700 | [diff] [blame] | 141 | } |