blob: 23558c802fe011a281a71b1ee81ca6d6518f4912 [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
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.Port;
24import org.onosproject.net.Device;
25import org.onosproject.net.device.DeviceService;
Jian Lia09f3c32018-10-08 10:48:34 +090026import org.onosproject.openstacknode.api.NodeState;
Hyunsun Moon0d457362017-06-27 17:19:41 +090027import org.onosproject.openstacknode.api.OpenstackNode;
28import org.onosproject.openstacknode.api.OpenstackNodeService;
Jian Lia09f3c32018-10-08 10:48:34 +090029import org.openstack4j.api.OSClient;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070030
31import static org.onosproject.net.AnnotationKeys.PORT_NAME;
Jian Li5afbea42018-02-28 10:37:03 +090032import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL;
33import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
Jian Lia09f3c32018-10-08 10:48:34 +090034import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER;
35import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
36import static org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070037
38/**
39 * Checks detailed node init state.
40 */
41@Command(scope = "onos", name = "openstack-node-check",
42 description = "Shows detailed node init state")
43public class OpenstackNodeCheckCommand extends AbstractShellCommand {
44
45 @Argument(index = 0, name = "hostname", description = "Hostname",
46 required = true, multiValued = false)
47 private String hostname = null;
48
49 private static final String MSG_OK = "OK";
Jian Lia09f3c32018-10-08 10:48:34 +090050 private static final String MSG_ERROR = "ERROR";
Hyunsun Moon34bbe172016-06-28 19:18:40 -070051
52 @Override
53 protected void execute() {
Hyunsun Moon0d457362017-06-27 17:19:41 +090054 OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070055 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
56
Hyunsun Moon0d457362017-06-27 17:19:41 +090057 OpenstackNode osNode = osNodeService.node(hostname);
58 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090059 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070060 return;
61 }
62
Jian Lia09f3c32018-10-08 10:48:34 +090063 if (osNode.type() == CONTROLLER) {
64 print("[Openstack Controller Status]");
65
66 OSClient client = getConnectedClient(osNode);
67 if (client == null) {
68 error("The given keystone info is incorrect to get authorized to openstack");
69 print("keystoneConfig=%s", osNode.keystoneConfig());
Hyunsun Moon0d457362017-06-27 17:19:41 +090070 }
Jian Lia09f3c32018-10-08 10:48:34 +090071
72 if (osNode.keystoneConfig() != null) {
73 print("%s keystoneConfig=%s, neutronConfig=%s",
74 osNode.state() == NodeState.COMPLETE && client != null ?
75 MSG_OK : MSG_ERROR,
76 osNode.keystoneConfig(),
77 osNode.neutronConfig());
78 } else {
79 print("%s keystoneConfig is missing", MSG_ERROR);
daniel parkb18424c2018-02-05 15:43:43 +090080 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070081 } else {
Jian Lia09f3c32018-10-08 10:48:34 +090082 print("[Integration Bridge Status]");
83 Device device = deviceService.getDevice(osNode.intgBridge());
84 if (device != null) {
85 print("%s %s=%s available=%s %s",
86 deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR,
87 INTEGRATION_BRIDGE,
88 device.id(),
89 deviceService.isAvailable(device.id()),
90 device.annotations());
91 if (osNode.dataIp() != null) {
92 printPortState(deviceService, osNode.intgBridge(), DEFAULT_TUNNEL);
93 }
94 if (osNode.vlanIntf() != null) {
95 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
96 }
97 if (osNode.type() == GATEWAY) {
98 printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
99 }
100 } else {
101 print("%s %s=%s is not available",
102 MSG_ERROR,
103 INTEGRATION_BRIDGE,
104 osNode.intgBridge());
105 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700106 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700107 }
108
Hyunsun Moona9465642017-06-29 16:28:58 +0900109 private void printPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700110 Port port = deviceService.getPorts(deviceId).stream()
111 .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
112 p.isEnabled())
113 .findAny().orElse(null);
114
115 if (port != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +0900116 print("%s %s portNum=%s enabled=%s %s",
Jian Lia09f3c32018-10-08 10:48:34 +0900117 port.isEnabled() ? MSG_OK : MSG_ERROR,
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700118 portName,
119 port.number(),
120 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
121 port.annotations());
122 } else {
Jian Lia09f3c32018-10-08 10:48:34 +0900123 print("%s %s does not exist", MSG_ERROR, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700124 }
125 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700126}