blob: 057f29e8a0109277ce7c30e0b7c0b64f56fb7d98 [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 Li2d68c192018-12-13 15:52:59 +090034import static org.onosproject.openstacknode.api.Constants.GRE_TUNNEL;
35import static org.onosproject.openstacknode.api.Constants.VXLAN_TUNNEL;
Jian Li5afbea42018-02-28 10:37:03 +090036import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
Jian Lia09f3c32018-10-08 10:48:34 +090037import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER;
38import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
39import static org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070040
41/**
42 * Checks detailed node init state.
43 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070044@Service
Hyunsun Moon34bbe172016-06-28 19:18:40 -070045@Command(scope = "onos", name = "openstack-node-check",
46 description = "Shows detailed node init state")
47public class OpenstackNodeCheckCommand extends AbstractShellCommand {
48
49 @Argument(index = 0, name = "hostname", description = "Hostname",
50 required = true, multiValued = false)
Jian Lidb521c12018-11-19 17:42:35 +090051 @Completion(OpenstackHostnameCompleter.class)
Hyunsun Moon34bbe172016-06-28 19:18:40 -070052 private String hostname = null;
53
54 private static final String MSG_OK = "OK";
Jian Lia09f3c32018-10-08 10:48:34 +090055 private static final String MSG_ERROR = "ERROR";
Hyunsun Moon34bbe172016-06-28 19:18:40 -070056
57 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070058 protected void doExecute() {
Jian Li5ecfd1a2018-12-10 11:41:03 +090059 OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
60 DeviceService deviceService = get(DeviceService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070061
Hyunsun Moon0d457362017-06-27 17:19:41 +090062 OpenstackNode osNode = osNodeService.node(hostname);
63 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090064 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070065 return;
66 }
67
Jian Lia09f3c32018-10-08 10:48:34 +090068 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 Moon0d457362017-06-27 17:19:41 +090075 }
Jian Lia09f3c32018-10-08 10:48:34 +090076
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 parkb18424c2018-02-05 15:43:43 +090085 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070086 } else {
Jian Lia09f3c32018-10-08 10:48:34 +090087 print("[Integration Bridge Status]");
88 Device device = deviceService.getDevice(osNode.intgBridge());
Daniel Park0ba22e42019-04-11 18:22:50 +090089 Device ovsdbDevice = deviceService.getDevice(osNode.ovsdb());
Jian Lia09f3c32018-10-08 10:48:34 +090090 if (device != null) {
Daniel Park0ba22e42019-04-11 18:22:50 +090091 print("%s OvsdbDeviceId=%s available=%s",
92 deviceService.isAvailable(ovsdbDevice.id()) ? MSG_OK : MSG_ERROR,
93 ovsdbDevice.id(),
94 deviceService.isAvailable(ovsdbDevice.id()));
Jian Lia09f3c32018-10-08 10:48:34 +090095 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 Li2d68c192018-12-13 15:52:59 +0900102 printPortState(deviceService, osNode.intgBridge(), VXLAN_TUNNEL);
103 printPortState(deviceService, osNode.intgBridge(), GRE_TUNNEL);
Jian Lia09f3c32018-10-08 10:48:34 +0900104 }
105 if (osNode.vlanIntf() != null) {
106 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
107 }
Daniel Parkd45f0042019-03-27 14:48:33 +0900108 osNode.phyIntfs().forEach(intf -> {
109 printPortState(deviceService, osNode.intgBridge(), intf.intf());
110 });
Jian Lia09f3c32018-10-08 10:48:34 +0900111 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 Moon34bbe172016-06-28 19:18:40 -0700120 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700121 }
122
Jian Li5ecfd1a2018-12-10 11:41:03 +0900123 private void printPortState(DeviceService deviceService,
124 DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700125 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 Moona9465642017-06-29 16:28:58 +0900131 print("%s %s portNum=%s enabled=%s %s",
Jian Lia09f3c32018-10-08 10:48:34 +0900132 port.isEnabled() ? MSG_OK : MSG_ERROR,
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700133 portName,
134 port.number(),
135 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
136 port.annotations());
137 } else {
Jian Lia09f3c32018-10-08 10:48:34 +0900138 print("%s %s does not exist", MSG_ERROR, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700139 }
140 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700141}