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;
14 import org.apache.karaf.shell.api.action.Action;
15 import org.apache.karaf.shell.api.action.Command;
16 import org.apache.karaf.shell.api.action.Option;
17 import org.opendaylight.netconf.console.api.NetconfCommands;
18 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
20 @Command(name = "netconf:update-device", scope = "netconf", description = "Update netconf device attributes.")
21 public class NetconfUpdateDeviceCommand implements Action {
23 protected final NetconfCommands service;
25 public NetconfUpdateDeviceCommand(final NetconfCommands service) {
26 this.service = service;
30 NetconfUpdateDeviceCommand(final NetconfCommands service, final String newIp) {
31 this.service = service;
36 aliases = { "--nodeId" },
37 description = "NETCONF node ID of the netconf device",
40 private String deviceId;
43 aliases = { "--username" },
44 description = "Username for NETCONF connection",
47 private String username;
50 aliases = { "--password" },
51 description = "Password for NETCONF connection",
54 private String password;
57 aliases = { "--new-ipaddress" },
58 description = "New IP address of NETCONF device",
64 aliases = { "--new-port" },
65 description = "New Port of NETCONF device",
68 private String newPort;
71 aliases = { "--new-username" },
72 description = "New Username for NETCONF connection",
75 private String newUsername;
78 aliases = { "--new-password" },
79 description = "New Password for NETCONF connection",
82 private String newPassword;
85 aliases = { "--tcp-only" },
86 description = "Type of connection, true for tcp only",
89 private String newConnectionType = "false";
92 aliases = { "--schemaless" },
93 description = "Schemaless surpport, true for schemaless",
96 private String newSchemaless = "false";
99 public Object execute() {
101 Map<String, String> updated = new HashMap<>();
102 updated.put(NetconfConsoleConstants.NETCONF_IP, newIp);
103 updated.put(NetconfConsoleConstants.NETCONF_PORT, newPort);
104 updated.put(NetconfConsoleConstants.USERNAME, newUsername);
105 updated.put(NetconfConsoleConstants.PASSWORD, newPassword);
106 updated.put(NetconfConsoleConstants.TCP_ONLY, newConnectionType);
107 updated.put(NetconfConsoleConstants.SCHEMALESS,newSchemaless);
108 updated.values().remove(null);
110 if (updated.isEmpty()) {
111 return "Nothing to update.";
114 return service.updateDevice(deviceId, username, password, updated);