blob: 7f1d630ded7681ccc3c7b4537e0cdbee827d9061 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.Port;
25import org.onosproject.net.Device;
26import org.onosproject.net.device.DeviceService;
Jian Lia09f3c32018-10-08 10:48:34 +090027import org.onosproject.openstacknode.api.NodeState;
Hyunsun Moon0d457362017-06-27 17:19:41 +090028import org.onosproject.openstacknode.api.OpenstackNode;
29import org.onosproject.openstacknode.api.OpenstackNodeService;
Jian Lia09f3c32018-10-08 10:48:34 +090030import org.openstack4j.api.OSClient;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070031
32import static org.onosproject.net.AnnotationKeys.PORT_NAME;
Jian Li5afbea42018-02-28 10:37:03 +090033import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL;
34import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
Jian Lia09f3c32018-10-08 10:48:34 +090035import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER;
36import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
37import static org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070038
39/**
40 * Checks detailed node init state.
41 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070042@Service
Hyunsun Moon34bbe172016-06-28 19:18:40 -070043@Command(scope = "onos", name = "openstack-node-check",
44 description = "Shows detailed node init state")
45public class OpenstackNodeCheckCommand extends AbstractShellCommand {
46
47 @Argument(index = 0, name = "hostname", description = "Hostname",
48 required = true, multiValued = false)
49 private String hostname = null;
50
51 private static final String MSG_OK = "OK";
Jian Lia09f3c32018-10-08 10:48:34 +090052 private static final String MSG_ERROR = "ERROR";
Hyunsun Moon34bbe172016-06-28 19:18:40 -070053
54 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070055 protected void doExecute() {
Hyunsun Moon0d457362017-06-27 17:19:41 +090056 OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070057 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
58
Hyunsun Moon0d457362017-06-27 17:19:41 +090059 OpenstackNode osNode = osNodeService.node(hostname);
60 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090061 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070062 return;
63 }
64
Jian Lia09f3c32018-10-08 10:48:34 +090065 if (osNode.type() == CONTROLLER) {
66 print("[Openstack Controller Status]");
67
68 OSClient client = getConnectedClient(osNode);
69 if (client == null) {
70 error("The given keystone info is incorrect to get authorized to openstack");
71 print("keystoneConfig=%s", osNode.keystoneConfig());
Hyunsun Moon0d457362017-06-27 17:19:41 +090072 }
Jian Lia09f3c32018-10-08 10:48:34 +090073
74 if (osNode.keystoneConfig() != null) {
75 print("%s keystoneConfig=%s, neutronConfig=%s",
76 osNode.state() == NodeState.COMPLETE && client != null ?
77 MSG_OK : MSG_ERROR,
78 osNode.keystoneConfig(),
79 osNode.neutronConfig());
80 } else {
81 print("%s keystoneConfig is missing", MSG_ERROR);
daniel parkb18424c2018-02-05 15:43:43 +090082 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070083 } else {
Jian Lia09f3c32018-10-08 10:48:34 +090084 print("[Integration Bridge Status]");
85 Device device = deviceService.getDevice(osNode.intgBridge());
86 if (device != null) {
87 print("%s %s=%s available=%s %s",
88 deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR,
89 INTEGRATION_BRIDGE,
90 device.id(),
91 deviceService.isAvailable(device.id()),
92 device.annotations());
93 if (osNode.dataIp() != null) {
94 printPortState(deviceService, osNode.intgBridge(), DEFAULT_TUNNEL);
95 }
96 if (osNode.vlanIntf() != null) {
97 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
98 }
99 if (osNode.type() == GATEWAY) {
100 printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
101 }
102 } else {
103 print("%s %s=%s is not available",
104 MSG_ERROR,
105 INTEGRATION_BRIDGE,
106 osNode.intgBridge());
107 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700108 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700109 }
110
Hyunsun Moona9465642017-06-29 16:28:58 +0900111 private void printPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700112 Port port = deviceService.getPorts(deviceId).stream()
113 .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
114 p.isEnabled())
115 .findAny().orElse(null);
116
117 if (port != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +0900118 print("%s %s portNum=%s enabled=%s %s",
Jian Lia09f3c32018-10-08 10:48:34 +0900119 port.isEnabled() ? MSG_OK : MSG_ERROR,
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700120 portName,
121 port.number(),
122 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
123 port.annotations());
124 } else {
Jian Lia09f3c32018-10-08 10:48:34 +0900125 print("%s %s does not exist", MSG_ERROR, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700126 }
127 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700128}