blob: 8289c98c1d86496dc60fe97bafc5ab6ba4bb7da3 [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;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070021import 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;
Hyunsun Moon0d457362017-06-27 17:19:41 +090026import org.onosproject.openstacknode.api.OpenstackNode;
27import org.onosproject.openstacknode.api.OpenstackNodeService;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070028
29import static org.onosproject.net.AnnotationKeys.PORT_NAME;
Jian Li5afbea42018-02-28 10:37:03 +090030import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL;
31import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070032
33/**
34 * Checks detailed node init state.
35 */
36@Command(scope = "onos", name = "openstack-node-check",
37 description = "Shows detailed node init state")
38public class OpenstackNodeCheckCommand extends AbstractShellCommand {
39
40 @Argument(index = 0, name = "hostname", description = "Hostname",
41 required = true, multiValued = false)
42 private String hostname = null;
43
44 private static final String MSG_OK = "OK";
45 private static final String MSG_NO = "NO";
46
47 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070048 protected void doExecute() {
Hyunsun Moon0d457362017-06-27 17:19:41 +090049 OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070050 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
51
Hyunsun Moon0d457362017-06-27 17:19:41 +090052 OpenstackNode osNode = osNodeService.node(hostname);
53 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090054 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070055 return;
56 }
57
Hyunsun Moon052c71f2016-07-11 18:56:18 -070058 print("[Integration Bridge Status]");
Hyunsun Moon0d457362017-06-27 17:19:41 +090059 Device device = deviceService.getDevice(osNode.intgBridge());
Hyunsun Moon34bbe172016-06-28 19:18:40 -070060 if (device != null) {
61 print("%s %s=%s available=%s %s",
62 deviceService.isAvailable(device.id()) ? MSG_OK : MSG_NO,
63 INTEGRATION_BRIDGE,
64 device.id(),
65 deviceService.isAvailable(device.id()),
66 device.annotations());
Hyunsun Moon0d457362017-06-27 17:19:41 +090067 if (osNode.dataIp() != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090068 printPortState(deviceService, osNode.intgBridge(), DEFAULT_TUNNEL);
Hyunsun Moon0d457362017-06-27 17:19:41 +090069 }
70 if (osNode.vlanIntf() != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090071 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
Hyunsun Moon0d457362017-06-27 17:19:41 +090072 }
daniel parkb18424c2018-02-05 15:43:43 +090073 if (osNode.type() == OpenstackNode.NodeType.GATEWAY) {
74 printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
75 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070076 } else {
77 print("%s %s=%s is not available",
78 MSG_NO,
79 INTEGRATION_BRIDGE,
Hyunsun Moon0d457362017-06-27 17:19:41 +090080 osNode.intgBridge());
Hyunsun Moon34bbe172016-06-28 19:18:40 -070081 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070082 }
83
Hyunsun Moona9465642017-06-29 16:28:58 +090084 private void printPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -070085 Port port = deviceService.getPorts(deviceId).stream()
86 .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
87 p.isEnabled())
88 .findAny().orElse(null);
89
90 if (port != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090091 print("%s %s portNum=%s enabled=%s %s",
Hyunsun Moon34bbe172016-06-28 19:18:40 -070092 port.isEnabled() ? MSG_OK : MSG_NO,
93 portName,
94 port.number(),
95 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
96 port.annotations());
97 } else {
Hyunsun Moona9465642017-06-29 16:28:58 +090098 print("%s %s does not exist", MSG_NO, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070099 }
100 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700101}