- sshJcraftWrapper.send(terminateConnectionCmd);
- sshJcraftWrapper.closeConnection();
- sshJcraftWrapper = null;
- return(setResponseStatus(ctx, r));
- }
- catch (Exception e)
- {
- log(fnName, "Caught an Exception, e="+e);
- log(fnName, "StackTrace="+DebugLog.getStackTraceString(e));
- sshJcraftWrapper.closeConnection();
- r.code = HttpURLConnection.HTTP_INTERNAL_ERROR;
- r.message = e.getMessage();
- sshJcraftWrapper = null;
- log(fnName, "Returning error message");
- return (setResponseStatus(ctx, r));
- }
- }
- if(key.equals("xml-getrunningconfig"))
- {
- log(fnName, "key was: : xml-getrunningconfig");
- String xmlGetRunningConfigCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\"> <get-config> <source> <running /> </source> </get-config> </rpc>\n";
- String Host_ip_address = parameters.get("Host_ip_address");
- String User_name = parameters.get("User_name");
- String Password = parameters.get("Password");
- Password = EncryptionTool.getInstance().decrypt(Password);
- String Port_number = parameters.get("Port_number");
- String Protocol = parameters.get("Protocol");
- String netconfHelloCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n <capabilities>\n <capability>urn:ietf:params:netconf:base:1.0</capability>\n <capability>urn:com:ericsson:ebase:1.1.0</capability> </capabilities>\n </hello>";
- String terminateConnectionCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <rpc message-id=\"terminateConnection\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n <close-session/> \n </rpc>\n ]]>]]>";
- log(fnName, "xml-getrunningconfig: User_name="+User_name +" Host_ip_address="+Host_ip_address +" Password="+Password +" Port_number="+Port_number);
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
- try
- {
- String NetconfHelloCmd = netconfHelloCmd;
- sshJcraftWrapper.connect (Host_ip_address, User_name, Password, "]]>]]>", 30000, Integer.parseInt(Port_number), "netconf");
- NetconfHelloCmd = NetconfHelloCmd +"]]>]]>";
- log(fnName, ":Sending the hello command");
- sshJcraftWrapper.send(NetconfHelloCmd);
- String response = sshJcraftWrapper.receiveUntil("]]>]]>", 10000, "");
- log(fnName, "Sending get running config command");
- sshJcraftWrapper.send(xmlGetRunningConfigCmd +"]]>]]>\n");
- response = sshJcraftWrapper.receiveUntil("</rpc-reply>", 180000, "");
- DebugLog.printAriDebug(fnName,"Response from getRunningconfigCmd="+response);
- response = trimResponse(response);
- ctx.setAttribute("xmlRunningConfigOutput", response);
- sshJcraftWrapper.send(terminateConnectionCmd);
- sshJcraftWrapper.closeConnection();
- r.code = 200;
- sshJcraftWrapper = null;
- return(setResponseStatus(ctx, r));
- }
- catch (Exception e)
- {
- log(fnName, "Caught an Exception, e="+e);
- log(fnName, "StackTrace="+DebugLog.getStackTraceString(e));
- sshJcraftWrapper.closeConnection();
- r.code = HttpURLConnection.HTTP_INTERNAL_ERROR;
- r.message = e.getMessage();
- sshJcraftWrapper = null;
- log(fnName, "Returning error message");
- return (setResponseStatus(ctx, r));
- }
- }
- if(key.equals("DownloadCliConfig"))
- {
- debugLog.printRTAriDebug (fnName, "key was: DownloadCliConfig: ");
- log.debug("key was: DownloadCliConfig: ");
- String User_name = parameters.get("User_name");
- String Host_ip_address = parameters.get("Host_ip_address");
- String Password = parameters.get("Password");
- Password = EncryptionTool.getInstance().decrypt(Password);
- String Port_number = parameters.get("Port_number");
- String Download_config_template = parameters.get("Download_config_template");
- String Config_contents = parameters.get("Config_contents");
- DebugLog.printAriDebug(fnName, "Contents of the 'Config_contents' are: "+Config_contents);
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
- log.debug("DownloadCliConfig: sshJcraftWrapper was instantiated");
- debugLog.printRTAriDebug (fnName, "DownloadCliConfig: sshJcraftWrapper was instantiated");
- int timeout = 4*60*1000;
- try
- {
- DebugLog.printAriDebug(fnName, "DownloadCliConfig: User_name="+User_name +" Host_ip_address="+Host_ip_address +" Password="+Password +" Port_number="+Port_number);
- log.debug("DownloadCliConfig: Attempting to login: Host_ip_address="+Host_ip_address +" User_name="+User_name+" Password="+Password+" Port_number="+Port_number);
- StringBuffer sb = new StringBuffer();
- String response = "";
- String CliResponse = "";
- sshJcraftWrapper.connect (Host_ip_address, User_name, Password, "", 30000, Integer.parseInt(Port_number));
- DebugLog.printAriDebug(fnName, "DownloadCliConfig: On the VNF device");
- StringTokenizer st = new StringTokenizer(Download_config_template, "\n");
- String command = null;
- String executeConfigContentsDelemeter = null;
- try
- {
- while (st.hasMoreTokens())
- {
- String line = st.nextToken();
- DebugLog.printAriDebug(fnName, "line="+line);
- if (line.indexOf("Request:") != -1)
- {
- DebugLog.printAriDebug(fnName, "Found a Request line: line="+line);
- command = getStringBetweenQuotes(line);
- DebugLog.printAriDebug(fnName, "Sending command="+command);
- sshJcraftWrapper.send(command);
- DebugLog.printAriDebug(fnName, "command has been sent");
+ if (key.equals("GetCliRunningConfig")) {
+ debugLog.printRTAriDebug(fnName, "key was: GetCliRunningConfig: ");
+ log.debug("key was: GetCliRunningConfig: ");
+ String User_name = parameters.get("User_name");
+ String Host_ip_address = parameters.get("Host_ip_address");
+ String Password = parameters.get("Password");
+ Password = EncryptionTool.getInstance().decrypt(Password);
+ String Port_number = parameters.get("Port_number");
+ String Get_config_template = parameters.get("Get_config_template");
+ SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ log.debug("GetCliRunningConfig: sshJcraftWrapper was instantiated");
+ debugLog.printRTAriDebug(fnName, "GetCliRunningConfig: sshJcraftWrapper was instantiated");
+ try {
+ debugLog.printRTAriDebug(fnName,
+ "GetCliRunningConfig: User_name=" + User_name + " Host_ip_address=" + Host_ip_address + " Password="
+ + Password + " Port_number=" + Port_number);
+ log.debug("GetCliRunningConfig: Attempting to login: Host_ip_address=" + Host_ip_address + " User_name="
+ + User_name + " Password=" + Password + " Port_number=" + Port_number);
+ StringBuffer sb = new StringBuffer();
+ String response = "";
+ String CliResponse = "";
+ boolean showConfigFlag = false;
+ sshJcraftWrapper
+ .connect(Host_ip_address, User_name, Password, "", 30000, Integer.parseInt(Port_number));
+ debugLog.printRTAriDebug(fnName, "GetCliRunningConfig: On the VNF device");
+ StringTokenizer st = new StringTokenizer(Get_config_template, "\n");
+ String command = null;
+ try {
+ while (st.hasMoreTokens()) {
+ String line = st.nextToken();
+ debugLog.printRTAriDebug(fnName, "line=" + line);
+ if (line.indexOf("Request:") != -1) {
+ debugLog.printRTAriDebug(fnName, "Found a Request line: line=" + line);
+ command = getStringBetweenQuotes(line);
+ debugLog.printRTAriDebug(fnName, "Sending command=" + command);
+ sshJcraftWrapper.send(command);
+ debugLog.printRTAriDebug(fnName, "command has been sent");
+ if (line.indexOf("show config") != -1) {
+ showConfigFlag = true;
+ debugLog.printRTAriDebug(fnName, "GetCliRunningConfig: setting 'showConfigFlag' to true");
+ log.debug("GetCliRunningConfig: GetCliRunningConfig: setting 'showConfigFlag' to true");
+ }
+ }
+ if (line.indexOf("Response: Ends_With") != -1) {
+ debugLog.printRTAriDebug(fnName, "Found a Response line: line=" + line);
+ String delemeter = getStringBetweenQuotes(line);
+ debugLog.printRTAriDebug(fnName, "The delemeter=" + delemeter);
+ String tmpResponse = sshJcraftWrapper.receiveUntil(delemeter, 120 * 1000, command);
+ response += tmpResponse;
+ if (showConfigFlag) {
+ showConfigFlag = false;
+ StringTokenizer st2 = new StringTokenizer(tmpResponse, "\n");
+ while (st2.hasMoreTokens()) {
+ String line2 = st2.nextToken();
+ if (line2.indexOf("#") == -1) {
+ CliResponse += line2 + "\n";
+ }
+ }
+ }
+ }
+ }
+ } catch (NoSuchElementException e) {
+ debugLog.printRTAriDebug(fnName, "Caught a NoSuchElementException: e=" + e);
+ }
+ debugLog.printRTAriDebug(fnName, "CliResponse=\n" + CliResponse);
+ ctx.setAttribute("cliOutput", CliResponse);
+ sshJcraftWrapper.closeConnection();
+ r.code = 200;
+ sshJcraftWrapper = null;
+ return (setResponseStatus(ctx, r));
+ } catch (IOException e) {
+ debugLog.printRTAriDebug(fnName, "GetCliRunningConfig: Caught a IOException e=" + e);
+ log.debug(fnName + " : GetCliRunningConfig: Caught a IOException e=" + e);
+ sshJcraftWrapper.closeConnection();
+ r.code = HttpURLConnection.HTTP_INTERNAL_ERROR;
+ r.message = e.getMessage();
+ sshJcraftWrapper = null;
+ debugLog.printRTAriDebug(fnName, "GetCliRunningConfig: Returning error message");
+ return (setResponseStatus(ctx, r));