blob: c8c6ba22e3f6aed32a5c93d4a0aed6940dbde02a [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;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.Port;
26import org.onosproject.net.Device;
27import 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 Li5afbea42018-02-28 10:37:03 +090034import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL;
35import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
Jian Lia09f3c32018-10-08 10:48:34 +090036import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER;
37import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
38import static org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070039
40/**
41 * Checks detailed node init state.
42 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070043@Service
Hyunsun Moon34bbe172016-06-28 19:18:40 -070044@Command(scope = "onos", name = "openstack-node-check",
45 description = "Shows detailed node init state")
46public class OpenstackNodeCheckCommand extends AbstractShellCommand {
47
48 @Argument(index = 0, name = "hostname", description = "Hostname",
49 required = true, multiValued = false)
Jian Lidb521c12018-11-19 17:42:35 +090050 @Completion(OpenstackHostnameCompleter.class)
Hyunsun Moon34bbe172016-06-28 19:18:40 -070051 private String hostname = null;
52
53 private static final String MSG_OK = "OK";
Jian Lia09f3c32018-10-08 10:48:34 +090054 private static final String MSG_ERROR = "ERROR";
Hyunsun Moon34bbe172016-06-28 19:18:40 -070055
56 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070057 protected void doExecute() {
Hyunsun Moon0d457362017-06-27 17:19:41 +090058 OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070059 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
60
Hyunsun Moon0d457362017-06-27 17:19:41 +090061 OpenstackNode osNode = osNodeService.node(hostname);
62 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090063 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070064 return;
65 }
66
Jian Lia09f3c32018-10-08 10:48:34 +090067 if (osNode.type() == CONTROLLER) {
68 print("[Openstack Controller Status]");
69
70 OSClient client = getConnectedClient(osNode);
71 if (client == null) {
72 error("The given keystone info is incorrect to get authorized to openstack");
73 print("keystoneConfig=%s", osNode.keystoneConfig());
Hyunsun Moon0d457362017-06-27 17:19:41 +090074 }
Jian Lia09f3c32018-10-08 10:48:34 +090075
76 if (osNode.keystoneConfig() != null) {
77 print("%s keystoneConfig=%s, neutronConfig=%s",
78 osNode.state() == NodeState.COMPLETE && client != null ?
79 MSG_OK : MSG_ERROR,
80 osNode.keystoneConfig(),
81 osNode.neutronConfig());
82 } else {
83 print("%s keystoneConfig is missing", MSG_ERROR);
daniel parkb18424c2018-02-05 15:43:43 +090084 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070085 } else {
Jian Lia09f3c32018-10-08 10:48:34 +090086 print("[Integration Bridge Status]");
87 Device device = deviceService.getDevice(osNode.intgBridge());
88 if (device != null) {
89 print("%s %s=%s available=%s %s",
90 deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR,
91 INTEGRATION_BRIDGE,
92 device.id(),
93 deviceService.isAvailable(device.id()),
94 device.annotations());
95 if (osNode.dataIp() != null) {
96 printPortState(deviceService, osNode.intgBridge(), DEFAULT_TUNNEL);
97 }
98 if (osNode.vlanIntf() != null) {
99 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
100 }
101 if (osNode.type() == GATEWAY) {
102 printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
103 }
104 } else {
105 print("%s %s=%s is not available",
106 MSG_ERROR,
107 INTEGRATION_BRIDGE,
108 osNode.intgBridge());
109 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700110 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700111 }
112
Hyunsun Moona9465642017-06-29 16:28:58 +0900113 private void printPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700114 Port port = deviceService.getPorts(deviceId).stream()
115 .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
116 p.isEnabled())
117 .findAny().orElse(null);
118
119 if (port != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +0900120 print("%s %s portNum=%s enabled=%s %s",
Jian Lia09f3c32018-10-08 10:48:34 +0900121 port.isEnabled() ? MSG_OK : MSG_ERROR,
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700122 portName,
123 port.number(),
124 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
125 port.annotations());
126 } else {
Jian Lia09f3c32018-10-08 10:48:34 +0900127 print("%s %s does not exist", MSG_ERROR, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700128 }
129 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700130}