Pearl1594 commented on a change in pull request #5831:
URL: https://github.com/apache/cloudstack/pull/5831#discussion_r803294694



##########
File path: utils/src/main/java/com/cloud/utils/ssh/SshHelper.java
##########
@@ -118,6 +124,42 @@ public static void scpTo(String host, int port, String 
user, File pemKeyFile, St
         }
     }
 
+    public static void scpTo(String host, int port, String user, File 
pemKeyFile, String password, String remoteTargetDirectory, String[] localFiles, 
String fileMode,
+                             int connectTimeoutInMs, int kexTimeoutInMs) 
throws Exception {
+
+        com.trilead.ssh2.Connection conn = null;
+        com.trilead.ssh2.SCPClient scpClient = null;
+
+        try {
+            conn = new com.trilead.ssh2.Connection(host, port);
+            conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
+
+            if (pemKeyFile == null) {
+                if (!conn.authenticateWithPassword(user, password)) {
+                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
+                    s_logger.error(msg);
+                    throw new Exception(msg);
+                }
+            } else {
+                if (!conn.authenticateWithPublicKey(user, pemKeyFile, 
password)) {
+                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
+                    s_logger.error(msg);
+                    throw new Exception(msg);

Review comment:
       This follows old implementation

##########
File path: utils/src/main/java/com/cloud/utils/ssh/SshHelper.java
##########
@@ -118,6 +124,42 @@ public static void scpTo(String host, int port, String 
user, File pemKeyFile, St
         }
     }
 
+    public static void scpTo(String host, int port, String user, File 
pemKeyFile, String password, String remoteTargetDirectory, String[] localFiles, 
String fileMode,
+                             int connectTimeoutInMs, int kexTimeoutInMs) 
throws Exception {
+
+        com.trilead.ssh2.Connection conn = null;
+        com.trilead.ssh2.SCPClient scpClient = null;
+
+        try {
+            conn = new com.trilead.ssh2.Connection(host, port);
+            conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
+
+            if (pemKeyFile == null) {
+                if (!conn.authenticateWithPassword(user, password)) {
+                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
+                    s_logger.error(msg);
+                    throw new Exception(msg);

Review comment:
       This follows old implementation

##########
File path: utils/src/main/java/com/cloud/utils/FileUtil.java
##########
@@ -21,12 +21,39 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
 
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.ssh.SshHelper;
 import org.apache.commons.io.FileUtils;
+import org.apache.log4j.Logger;
 
 public class FileUtil {
+    private static final Logger s_logger = Logger.getLogger(FileUtil.class);
 
     public static void copyfile(File source, File destination) throws 
IOException {
         FileUtils.copyFile(source, destination);
     }
+
+    public static void scpPatchFiles(String controlIp, String destPath, int 
sshPort, File pemFile, String[] files, String basePath) {
+        String errMsg = "Failed to scp files to system VM";
+        List<String> srcFiles = Arrays.asList(files);
+        srcFiles = srcFiles.stream()
+                .map(file -> basePath + file) // Using Lambda notation to 
update the entries
+                .collect(Collectors.toList());
+        String[] newSrcFiles = srcFiles.toArray(new String[0]);
+        for (int retries = 3; retries > 0; retries--) {
+            try {
+                SshHelper.scpTo(controlIp, sshPort, "root", pemFile, null,
+                        destPath, newSrcFiles, "0755");
+                return;
+            } catch (Exception e) {

Review comment:
       This follows old implementation




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to