2 * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netconf.console.commands;
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.base.Strings;
13 import org.apache.karaf.shell.api.action.Action;
14 import org.apache.karaf.shell.api.action.Command;
15 import org.apache.karaf.shell.api.action.Option;
16 import org.opendaylight.netconf.console.api.NetconfCommands;
18 @Command(name = "netconf:disconnect-device", scope = "netconf", description = "Disconnect netconf device.")
19 public class NetconfDisconnectDeviceCommand implements Action {
21 protected final NetconfCommands service;
23 public NetconfDisconnectDeviceCommand(final NetconfCommands service) {
24 this.service = service;
28 NetconfDisconnectDeviceCommand(final NetconfCommands service, final String deviceId, final String deviceIp,
29 final String devicePort) {
30 this.service = service;
31 this.deviceId = deviceId;
32 this.deviceIp = deviceIp;
33 this.devicePort = devicePort;
37 aliases = { "--ipaddress" },
38 description = "IP address of the netconf device",
41 private String deviceIp;
44 aliases = { "--port" },
45 description = "Port of the netconf device",
48 private String devicePort;
51 aliases = { "--identifier" },
52 description = "Node Identifier of the netconf device",
55 private String deviceId;
58 public Object execute() {
59 boolean status = false;
60 if (!Strings.isNullOrEmpty(deviceId)) {
61 status = service.disconnectDevice(deviceId);
63 if (!NetconfCommandUtils.isIpValid(deviceIp) || !NetconfCommandUtils.isPortValid(devicePort)) {
64 return "Invalid IP:" + deviceIp + " or Port:" + devicePort + "Please enter a valid entry to proceed.";
66 status = service.disconnectDevice(deviceIp, devicePort);
68 final String message = status ? "Netconf connector disconnected succesfully"
69 : "Failed to disconnect netconf connector. Refer to karaf.log for details.";