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 java.util.HashMap;
15 import org.apache.karaf.shell.commands.Command;
16 import org.apache.karaf.shell.commands.Option;
17 import org.apache.karaf.shell.console.AbstractAction;
18 import org.opendaylight.netconf.console.api.NetconfCommands;
19 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
21 @Command(name = "netconf:update-device", scope = "netconf", description = "Update netconf device attributes.")
22 public class NetconfUpdateDeviceCommand extends AbstractAction {
24 protected final NetconfCommands service;
26 public NetconfUpdateDeviceCommand(final NetconfCommands service) {
27 this.service = service;
31 NetconfUpdateDeviceCommand(final NetconfCommands service, final String newIp) {
32 this.service = service;
37 aliases = { "--nodeId" },
38 description = "NETCONF node ID of the netconf device",
41 private String deviceId;
44 aliases = { "--username" },
45 description = "Username for NETCONF connection",
48 private String username;
51 aliases = { "--password" },
52 description = "Password for NETCONF connection",
55 private String password;
58 aliases = { "--new-ipaddress" },
59 description = "New IP address of NETCONF device",
65 aliases = { "--new-port" },
66 description = "New Port of NETCONF device",
69 private String newPort;
72 aliases = { "--new-username" },
73 description = "New Username for NETCONF connection",
76 private String newUsername;
79 aliases = { "--new-password" },
80 description = "New Password for NETCONF connection",
83 private String newPassword;
86 aliases = { "--tcp-only" },
87 description = "Type of connection, true for tcp only",
90 private String newConnectionType = "false";
93 protected Object doExecute() throws Exception {
95 Map<String, String> updated = new HashMap<>();
96 updated.put(NetconfConsoleConstants.NETCONF_IP, newIp);
97 updated.put(NetconfConsoleConstants.NETCONF_PORT, newPort);
98 updated.put(NetconfConsoleConstants.USERNAME, newUsername);
99 updated.put(NetconfConsoleConstants.PASSWORD, newPassword);
100 updated.put(NetconfConsoleConstants.TCP_ONLY, newConnectionType);
101 updated.values().remove(null);
103 if (updated.isEmpty()) {
104 return "Nothing to update.";
106 String statusMessage = service.updateDevice(deviceId, username, password, updated);
107 return statusMessage;