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",
52 private String username;
55 aliases = { "--password" },
56 description = "Password for NETCONF connection",
60 private String password;
63 aliases = { "--new-ipaddress" },
64 description = "New IP address of NETCONF device",
70 aliases = { "--new-port" },
71 description = "New Port of NETCONF device",
74 private String newPort;
77 aliases = { "--new-username" },
78 description = "New Username for NETCONF connection",
81 private String newUsername;
84 aliases = { "--new-password" },
85 description = "New Password for NETCONF connection",
88 private String newPassword;
91 aliases = { "--tcp-only" },
92 description = "Type of connection, true for tcp only",
95 private String newConnectionType = "false";
98 aliases = { "--schemaless" },
99 description = "Schemaless surpport, true for schemaless",
102 private String newSchemaless = "false";
105 public Object execute() {
106 Map<String, String> updated = new HashMap<>();
107 updated.put(NetconfConsoleConstants.NETCONF_IP, newIp);
108 updated.put(NetconfConsoleConstants.NETCONF_PORT, newPort);
109 updated.put(NetconfConsoleConstants.USERNAME, newUsername);
110 updated.put(NetconfConsoleConstants.PASSWORD, newPassword);
111 updated.put(NetconfConsoleConstants.TCP_ONLY, newConnectionType);
112 updated.put(NetconfConsoleConstants.SCHEMALESS,newSchemaless);
113 updated.values().remove(null);
115 if (updated.isEmpty()) {
116 return "Nothing to update.";
119 return service.updateDevice(deviceId, username, password, updated);