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.apache.karaf.shell.api.action.lifecycle.Reference;
18 import org.apache.karaf.shell.api.action.lifecycle.Service;
19 import org.opendaylight.netconf.console.api.NetconfCommands;
20 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
23 @Command(name = "update-device", scope = "netconf", description = "Update netconf device attributes.")
24 public class NetconfUpdateDeviceCommand implements Action {
27 private NetconfCommands service;
29 public NetconfUpdateDeviceCommand() {
34 NetconfUpdateDeviceCommand(final NetconfCommands service, final String newIp) {
35 this.service = service;
40 aliases = { "--nodeId" },
41 description = "NETCONF node ID of the netconf device",
44 private String deviceId;
47 aliases = { "--username" },
48 description = "Username for NETCONF connection",
51 private String username;
54 aliases = { "--password" },
55 description = "Password for NETCONF connection",
58 private String password;
61 aliases = { "--new-ipaddress" },
62 description = "New IP address of NETCONF device",
68 aliases = { "--new-port" },
69 description = "New Port of NETCONF device",
72 private String newPort;
75 aliases = { "--new-username" },
76 description = "New Username for NETCONF connection",
79 private String newUsername;
82 aliases = { "--new-password" },
83 description = "New Password for NETCONF connection",
86 private String newPassword;
89 aliases = { "--tcp-only" },
90 description = "Type of connection, true for tcp only",
93 private String newConnectionType = "false";
96 aliases = { "--schemaless" },
97 description = "Schemaless surpport, true for schemaless",
100 private String newSchemaless = "false";
103 public Object execute() {
104 Map<String, String> updated = new HashMap<>();
105 updated.put(NetconfConsoleConstants.NETCONF_IP, newIp);
106 updated.put(NetconfConsoleConstants.NETCONF_PORT, newPort);
107 updated.put(NetconfConsoleConstants.USERNAME, newUsername);
108 updated.put(NetconfConsoleConstants.PASSWORD, newPassword);
109 updated.put(NetconfConsoleConstants.TCP_ONLY, newConnectionType);
110 updated.put(NetconfConsoleConstants.SCHEMALESS,newSchemaless);
111 updated.values().remove(null);
113 if (updated.isEmpty()) {
114 return "Nothing to update.";
117 return service.updateDevice(deviceId, username, password, updated);