blob: b10a9190527c40dfef46b7083eec55cb8b083cbc [file] [log] [blame]
Hyunsun Moon34bbe172016-06-28 19:18:40 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Hyunsun Moon34bbe172016-06-28 19:18:40 -07003 *
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
17package org.onosproject.openstacknode.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Jian Lidb521c12018-11-19 17:42:35 +090021import org.apache.karaf.shell.api.action.Completion;
Ray Milkey7a2dee52018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070023import org.onosproject.cli.AbstractShellCommand;
Jian Li5ecfd1a2018-12-10 11:41:03 +090024import org.onosproject.net.Device;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070025import org.onosproject.net.DeviceId;
26import org.onosproject.net.Port;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070027import org.onosproject.net.device.DeviceService;
Jian Lia09f3c32018-10-08 10:48:34 +090028import org.onosproject.openstacknode.api.NodeState;
Hyunsun Moon0d457362017-06-27 17:19:41 +090029import org.onosproject.openstacknode.api.OpenstackNode;
30import org.onosproject.openstacknode.api.OpenstackNodeService;
Jian Lia09f3c32018-10-08 10:48:34 +090031import org.openstack4j.api.OSClient;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070032
33import static org.onosproject.net.AnnotationKeys.PORT_NAME;
Jian Lifba7e482019-09-18 13:23:25 +090034import static org.onosproject.openstacknode.api.Constants.GENEVE_TUNNEL;
Jian Li2d68c192018-12-13 15:52:59 +090035import static org.onosproject.openstacknode.api.Constants.GRE_TUNNEL;
Jian Li5afbea42018-02-28 10:37:03 +090036import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
Jian Li62116942019-09-03 23:10:20 +090037import static org.onosproject.openstacknode.api.Constants.INTEGRATION_TO_PHYSICAL_PREFIX;
38import static org.onosproject.openstacknode.api.Constants.VXLAN_TUNNEL;
Jian Lia09f3c32018-10-08 10:48:34 +090039import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER;
40import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
41import static org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient;
Jian Li62116942019-09-03 23:10:20 +090042import static org.onosproject.openstacknode.util.OpenstackNodeUtil.structurePortName;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070043
44/**
45 * Checks detailed node init state.
46 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070047@Service
Hyunsun Moon34bbe172016-06-28 19:18:40 -070048@Command(scope = "onos", name = "openstack-node-check",
49 description = "Shows detailed node init state")
50public class OpenstackNodeCheckCommand extends AbstractShellCommand {
51
52 @Argument(index = 0, name = "hostname", description = "Hostname",
53 required = true, multiValued = false)
Jian Lidb521c12018-11-19 17:42:35 +090054 @Completion(OpenstackHostnameCompleter.class)
Hyunsun Moon34bbe172016-06-28 19:18:40 -070055 private String hostname = null;
56
57 private static final String MSG_OK = "OK";
Jian Lia09f3c32018-10-08 10:48:34 +090058 private static final String MSG_ERROR = "ERROR";
Hyunsun Moon34bbe172016-06-28 19:18:40 -070059
60 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070061 protected void doExecute() {
Jian Li5ecfd1a2018-12-10 11:41:03 +090062 OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
63 DeviceService deviceService = get(DeviceService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070064
Hyunsun Moon0d457362017-06-27 17:19:41 +090065 OpenstackNode osNode = osNodeService.node(hostname);
66 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090067 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070068 return;
69 }
70
Jian Lia09f3c32018-10-08 10:48:34 +090071 if (osNode.type() == CONTROLLER) {
72 print("[Openstack Controller Status]");
73
74 OSClient client = getConnectedClient(osNode);
75 if (client == null) {
76 error("The given keystone info is incorrect to get authorized to openstack");
77 print("keystoneConfig=%s", osNode.keystoneConfig());
Hyunsun Moon0d457362017-06-27 17:19:41 +090078 }
Jian Lia09f3c32018-10-08 10:48:34 +090079
80 if (osNode.keystoneConfig() != null) {
81 print("%s keystoneConfig=%s, neutronConfig=%s",
82 osNode.state() == NodeState.COMPLETE && client != null ?
83 MSG_OK : MSG_ERROR,
84 osNode.keystoneConfig(),
85 osNode.neutronConfig());
86 } else {
87 print("%s keystoneConfig is missing", MSG_ERROR);
daniel parkb18424c2018-02-05 15:43:43 +090088 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070089 } else {
Jian Lia09f3c32018-10-08 10:48:34 +090090 print("[Integration Bridge Status]");
91 Device device = deviceService.getDevice(osNode.intgBridge());
Daniel Park0ba22e42019-04-11 18:22:50 +090092 Device ovsdbDevice = deviceService.getDevice(osNode.ovsdb());
Jian Lia09f3c32018-10-08 10:48:34 +090093 if (device != null) {
Daniel Park0ba22e42019-04-11 18:22:50 +090094 print("%s OvsdbDeviceId=%s available=%s",
95 deviceService.isAvailable(ovsdbDevice.id()) ? MSG_OK : MSG_ERROR,
96 ovsdbDevice.id(),
97 deviceService.isAvailable(ovsdbDevice.id()));
Jian Lia09f3c32018-10-08 10:48:34 +090098 print("%s %s=%s available=%s %s",
99 deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR,
100 INTEGRATION_BRIDGE,
101 device.id(),
102 deviceService.isAvailable(device.id()),
103 device.annotations());
104 if (osNode.dataIp() != null) {
Jian Li2d68c192018-12-13 15:52:59 +0900105 printPortState(deviceService, osNode.intgBridge(), VXLAN_TUNNEL);
106 printPortState(deviceService, osNode.intgBridge(), GRE_TUNNEL);
Jian Lifba7e482019-09-18 13:23:25 +0900107 printPortState(deviceService, osNode.intgBridge(), GENEVE_TUNNEL);
Jian Lia09f3c32018-10-08 10:48:34 +0900108 }
109 if (osNode.vlanIntf() != null) {
110 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
111 }
Daniel Parkd45f0042019-03-27 14:48:33 +0900112 osNode.phyIntfs().forEach(intf -> {
Jian Li62116942019-09-03 23:10:20 +0900113 printPortState(deviceService, osNode.intgBridge(),
114 structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + intf.network()));
Daniel Parkd45f0042019-03-27 14:48:33 +0900115 });
Jian Lia09f3c32018-10-08 10:48:34 +0900116 if (osNode.type() == GATEWAY) {
117 printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
118 }
119 } else {
120 print("%s %s=%s is not available",
121 MSG_ERROR,
122 INTEGRATION_BRIDGE,
123 osNode.intgBridge());
124 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700125 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700126 }
127
Jian Li5ecfd1a2018-12-10 11:41:03 +0900128 private void printPortState(DeviceService deviceService,
129 DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700130 Port port = deviceService.getPorts(deviceId).stream()
131 .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
132 p.isEnabled())
133 .findAny().orElse(null);
134
135 if (port != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +0900136 print("%s %s portNum=%s enabled=%s %s",
Jian Lia09f3c32018-10-08 10:48:34 +0900137 port.isEnabled() ? MSG_OK : MSG_ERROR,
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700138 portName,
139 port.number(),
140 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
141 port.annotations());
142 } else {
Jian Lia09f3c32018-10-08 10:48:34 +0900143 print("%s %s does not exist", MSG_ERROR, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700144 }
145 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700146}