blob: 3ad60efca432495d759ac0fdba0dd0953e47cf37 [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
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import 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;
Hyunsun Moon0d457362017-06-27 17:19:41 +090030import static org.onosproject.openstacknode.api.Constants.*;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070031
32/**
33 * Checks detailed node init state.
34 */
35@Command(scope = "onos", name = "openstack-node-check",
36 description = "Shows detailed node init state")
37public class OpenstackNodeCheckCommand extends AbstractShellCommand {
38
39 @Argument(index = 0, name = "hostname", description = "Hostname",
40 required = true, multiValued = false)
41 private String hostname = null;
42
43 private static final String MSG_OK = "OK";
44 private static final String MSG_NO = "NO";
45
46 @Override
47 protected void execute() {
Hyunsun Moon0d457362017-06-27 17:19:41 +090048 OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070049 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
50
Hyunsun Moon0d457362017-06-27 17:19:41 +090051 OpenstackNode osNode = osNodeService.node(hostname);
52 if (osNode == null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090053 print("Cannot find %s from registered nodes", hostname);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070054 return;
55 }
56
Hyunsun Moon052c71f2016-07-11 18:56:18 -070057 print("[Integration Bridge Status]");
Hyunsun Moon0d457362017-06-27 17:19:41 +090058 Device device = deviceService.getDevice(osNode.intgBridge());
Hyunsun Moon34bbe172016-06-28 19:18:40 -070059 if (device != null) {
60 print("%s %s=%s available=%s %s",
61 deviceService.isAvailable(device.id()) ? MSG_OK : MSG_NO,
62 INTEGRATION_BRIDGE,
63 device.id(),
64 deviceService.isAvailable(device.id()),
65 device.annotations());
Hyunsun Moon0d457362017-06-27 17:19:41 +090066 if (osNode.dataIp() != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090067 printPortState(deviceService, osNode.intgBridge(), DEFAULT_TUNNEL);
Hyunsun Moon0d457362017-06-27 17:19:41 +090068 }
69 if (osNode.vlanIntf() != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090070 printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
Hyunsun Moon0d457362017-06-27 17:19:41 +090071 }
daniel parkb18424c2018-02-05 15:43:43 +090072 if (osNode.type() == OpenstackNode.NodeType.GATEWAY) {
73 printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
74 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070075 } else {
76 print("%s %s=%s is not available",
77 MSG_NO,
78 INTEGRATION_BRIDGE,
Hyunsun Moon0d457362017-06-27 17:19:41 +090079 osNode.intgBridge());
Hyunsun Moon34bbe172016-06-28 19:18:40 -070080 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -070081 }
82
Hyunsun Moona9465642017-06-29 16:28:58 +090083 private void printPortState(DeviceService deviceService, DeviceId deviceId, String portName) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -070084 Port port = deviceService.getPorts(deviceId).stream()
85 .filter(p -> p.annotations().value(PORT_NAME).equals(portName) &&
86 p.isEnabled())
87 .findAny().orElse(null);
88
89 if (port != null) {
Hyunsun Moona9465642017-06-29 16:28:58 +090090 print("%s %s portNum=%s enabled=%s %s",
Hyunsun Moon34bbe172016-06-28 19:18:40 -070091 port.isEnabled() ? MSG_OK : MSG_NO,
92 portName,
93 port.number(),
94 port.isEnabled() ? Boolean.TRUE : Boolean.FALSE,
95 port.annotations());
96 } else {
Hyunsun Moona9465642017-06-29 16:28:58 +090097 print("%s %s does not exist", MSG_NO, portName);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070098 }
99 }
Hyunsun Moon34bbe172016-06-28 19:18:40 -0700100}