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 org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
13 import org.apache.karaf.shell.console.AbstractAction;
14 import org.opendaylight.netconf.console.api.NetconfCommands;
16 import com.google.common.base.Strings;
18 @Command(name = "netconf:disconnect-device", scope = "netconf", description = "Disconnect netconf device.")
19 public class NetconfDisconnectDeviceCommand extends AbstractAction {
21 protected final NetconfCommands service;
23 public NetconfDisconnectDeviceCommand(final NetconfCommands service) {
24 this.service = service;
28 aliases = { "--ipaddress" },
29 description = "IP address of the netconf device",
32 private String deviceIp;
35 aliases = { "--port" },
36 description = "Port of the netconf device",
39 private String devicePort;
42 aliases = { "--identifier" },
43 description = "Node Identifier of the netconf device",
46 private String deviceId;
49 protected Object doExecute() throws Exception {
50 boolean status = false;
51 if (!Strings.isNullOrEmpty(deviceId)) {
52 status = service.disconnectDevice(deviceId);
54 if (!NetconfCommandUtils.isIpValid(deviceIp) && !NetconfCommandUtils.isPortValid(devicePort)) {
55 return "Invalid IP:" + deviceIp + " or Port:" + devicePort + "Please enter a valid entry to proceed.";
57 status = service.disconnectDevice(deviceIp, devicePort);
59 final String message = status ? "Netconf connector disconnected succesfully"
60 : "Failed to disconnect netconf connector. Refer to karaf.log for details.";