blob: c67ff5b6ef8f3e0399a5170855be8deddf0e8186 [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;
Hyunsun Moon0d457362017-06-27 17:19:41 +090027import org.onosproject.openstacknode.api.OpenstackNode;
28import org.onosproject.openstacknode.api.OpenstackNodeService;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070029
30import static org.onosproject.net.AnnotationKeys.PORT_NAME;
Jian Li5afbea42018-02-28 10:37:03 +090031import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL;
32import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070033
34/**
35 * Checks detailed node init state.
36 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070037@Service
Hyunsun Moon34bbe172016-06-28 19:18:40 -070038@Command(scope = "onos", name = "openstack-node-check",
39 description = "Shows detailed node init state")
40public class OpenstackNodeCheckCommand extends AbstractShellCommand {
41
42 @Argument(index = 0, name = "hostname", description = "Hostname",
43 required = true, multiValued = false)
44 private String hostname = null;
45
46 private static final String MSG_OK = "OK";
47 private static final String MSG_NO = "NO";
48
49 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070050 protected void doExecute() {
Hyunsun Moon0d457362017-06-27 17:19:41 +090051 OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070052 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
53
Hyunsun Moon0d457362017-06-27 17:19:41 +090054 OpenstackNode osNode = osNodeService.node(hostname);
55 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090056 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070057 return;
58 }
59
Hyunsun Moon052c71f2016-07-11 18:56:18 -070060 print("[Integration Bridge Status]");
Hyunsun Moon0d457362017-06-27 17:19:41 +090061 Device device = deviceService.getDevice(osNode.intgBridge());
Hyunsun Moon34bbe172016-06-28 19:18:40 -070062 if (device != null) {
63 print("%s %s=%s available=%s %s",
64 deviceService.isAvailable(device.id()) ? MSG_OK : MSG_NO,
65 INTEGRATION_BRIDGE,
66 device.id(),
67 deviceService.isAvailable(device.id()),
68 device.annotations());
Hyunsun Moon0d457362017-06-27 17:19:41 +090069 if (osNode.dataIp() != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090070 printPortState(deviceService, osNode.intgBridge(), DEFAULT_TUNNEL);
Hyunsun Moon0d457362017-06-27 17:19:41 +090071 }
72 if (osNode.vlanIntf() != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090073 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
Hyunsun Moon0d457362017-06-27 17:19:41 +090074 }
daniel parkb18424c2018-02-05 15:43:43 +090075 if (osNode.type() == OpenstackNode.NodeType.GATEWAY) {
76 printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
77 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070078 } else {
79 print("%s %s=%s is not available",
80 MSG_NO,
81 INTEGRATION_BRIDGE,
Hyunsun Moon0d457362017-06-27 17:19:41 +090082 osNode.intgBridge());
Hyunsun Moon34bbe172016-06-28 19:18:40 -070083 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070084 }
85
Hyunsun Moona9465642017-06-29 16:28:58 +090086 private void printPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -070087 Port port = deviceService.getPorts(deviceId).stream()
88 .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
89 p.isEnabled())
90 .findAny().orElse(null);
91
92 if (port != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090093 print("%s %s portNum=%s enabled=%s %s",
Hyunsun Moon34bbe172016-06-28 19:18:40 -070094 port.isEnabled() ? MSG_OK : MSG_NO,
95 portName,
96 port.number(),
97 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
98 port.annotations());
99 } else {
Hyunsun Moona9465642017-06-29 16:28:58 +0900100 print("%s %s does not exist", MSG_NO, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700101 }
102 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700103}