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.apache.karaf.shell.api.action.lifecycle.Reference;
17 import org.apache.karaf.shell.api.action.lifecycle.Service;
18 import org.opendaylight.netconf.console.api.NetconfCommands;
21 @Command(name = "disconnect-device", scope = "netconf", description = "Disconnect netconf device.")
22 public class NetconfDisconnectDeviceCommand implements Action {
25 private NetconfCommands service;
27 public NetconfDisconnectDeviceCommand() {
32 NetconfDisconnectDeviceCommand(final NetconfCommands service) {
33 this.service = service;
37 NetconfDisconnectDeviceCommand(final NetconfCommands service, final String deviceId, final String deviceIp,
38 final String devicePort) {
39 this.service = service;
40 this.deviceId = deviceId;
41 this.deviceIp = deviceIp;
42 this.devicePort = devicePort;
46 aliases = { "--ipaddress" },
47 description = "IP address of the netconf device",
50 private String deviceIp;
53 aliases = { "--port" },
54 description = "Port of the netconf device",
57 private String devicePort;
60 aliases = { "--identifier" },
61 description = "Node Identifier of the netconf device",
64 private String deviceId;
67 public Object execute() {
68 boolean status = false;
69 if (!Strings.isNullOrEmpty(deviceId)) {
70 status = service.disconnectDevice(deviceId);
72 if (!NetconfCommandUtils.isIpValid(deviceIp) || !NetconfCommandUtils.isPortValid(devicePort)) {
73 return "Invalid IP:" + deviceIp + " or Port:" + devicePort + "Please enter a valid entry to proceed.";
75 status = service.disconnectDevice(deviceIp, devicePort);
77 final String message = status ? "Netconf connector disconnected succesfully"
78 : "Failed to disconnect netconf connector. Refer to karaf.log for details.";