def checkFiles(self, filePaths, hostsPasswords, gatewayHosts=None, numberTrials=1, forceOperation = False, operationId=1): """ Check if file paths exists. filepaths -- List of file paths to check with this format: "userName@hostName:absolute_file_path" gatewayHosts -- Gateway hosts dictionary with this format: "userName1@hostName1:userName2@hostName2":"userName@hostName" hostsPasswords -- Passwords needed to connect to involved hosts with this format: "userName@hostName":"hostPassword" numberTrials -- Number of trials in error cases. forceOperation -- Flag to indicate if, when an error happens and number of trials is exceeded, the operation must continue with the rest of files. operationId -- Operation identifier. returns -- List of not located file paths. """ returnFilePaths = [] # As we are going to create a session for each target host we must get different target hosts. userAndHosts = self.__getDiferentHostsFromFilePaths(filePaths) for userAndHost in userAndHosts: resultFilePaths = self.__getFilePaths(filePaths, userAndHost) if (self.__isLocalCredential(userAndHost)): for resultFilePath in resultFilePaths: filePath = self.__getLocationAndFilePath(resultFilePath)[1] log.info("Checking: " + filePath) if (len (missingPaths(filePath)) != 0): returnFilePaths.append(filePath) log.info("Check fail!!") else: # Recover host credentials userName = self.__getUserAndHost(userAndHost)[0] hostName = self.__getUserAndHost(userAndHost)[1] hostPassword = hostsPasswords[userAndHost] # Create ssh session to remote host log.info("Connecting to: " + userName + "@" + hostName) self.ssh.connect(hostName, SSH_PORT, userName, hostPassword) self.sftp = self.ssh.open_sftp() for resultFilePath in resultFilePaths: filePath = self.__getLocationAndFilePath(resultFilePath)[1] log.info("Checking: " + filePath) try: self.sftp.lstat(filePath) except IOError: returnFilePaths.append(resultFilePath) log.info("Check fail!!") self.ssh.close() self.sftp.close() return returnFilePaths
def checkFiles(self, filePaths, hostsPasswords, gatewayHosts=None, numberTrials=1, forceOperation=False, operationId=1): """ Check if file paths exists. filepaths -- List of file paths to check with this format: "userName@hostName:absolute_file_path" gatewayHosts -- Gateway hosts dictionary with this format: "userName1@hostName1:userName2@hostName2":"userName@hostName" hostsPasswords -- Passwords needed to connect to involved hosts with this format: "userName@hostName":"hostPassword" numberTrials -- Number of trials in error cases. forceOperation -- Flag to indicate if, when an error happens and number of trials is exceeded, the operation must continue with the rest of files. operationId -- Operation identifier. returns -- List of not located file paths. """ returnFilePaths = [] # As we are going to create a session for each target host we must get different target hosts. userAndHosts = self.__getDiferentHostsFromFilePaths(filePaths) for userAndHost in userAndHosts: resultFilePaths = self.__getFilePaths(filePaths, userAndHost) if self.__isLocalCredential(userAndHost): for resultFilePath in resultFilePaths: filePath = self.__getLocationAndFilePath(resultFilePath)[1] log.info("Checking: " + filePath) if len(missingPaths(filePath)) != 0: returnFilePaths.append(filePath) log.info("Check fail!!") else: # Recover host credentials userName = self.__getUserAndHost(userAndHost)[0] hostName = self.__getUserAndHost(userAndHost)[1] hostPassword = hostsPasswords[userAndHost] # Create ssh session to remote host log.info("Connecting to: " + userName + "@" + hostName) self.ssh.connect(hostName, SSH_PORT, userName, hostPassword) self.sftp = self.ssh.open_sftp() for resultFilePath in resultFilePaths: filePath = self.__getLocationAndFilePath(resultFilePath)[1] log.info("Checking: " + filePath) try: self.sftp.lstat(filePath) except IOError: returnFilePaths.append(resultFilePath) log.info("Check fail!!") self.ssh.close() self.sftp.close() return returnFilePaths
def checkOneHostFiles(self, filePaths, hostName, userName, hostsPassword, gatewayHosts=None, numberTrials=1, forceOperation=False, operationId=1): """ Check if file paths exists. filepaths -- List of file paths to check with this format: ["absolute_file_path1","absolute_file_path2"] gatewayHosts -- Gateway hosts dictionary with this format: "userName1@hostName1:userName2@hostName2":"userName@hostName" hostsPasswords -- Passwords needed to connect to involved hosts with this format: "userName@hostName":"hostPassword" numberTrials -- Number of trials in error cases. forceOperation -- Flag to indicate if, when an error happens and number of trials is exceeded, the operation must continue with the rest of files. operationId -- Operation identifier. returns -- List of not located file paths. """ returnFilePaths = [] print( "**************************************** CHECKING******************************************" ) log.info("Connecting to: " + userName + "@" + hostName) self.ssh.connect(hostName, SSH_PORT, userName, hostsPassword) self.sftp = self.ssh.open_sftp() isLocalHost = self.__isLocalHost(hostName) for fileName in filePaths: log.info("Checking: " + fileName) if isLocalHost: if len(missingPaths(fileName)) != 0: returnFilePaths.append(fileName) log.info("Check fail!!") else: try: self.sftp.lstat(fileName) except IOError: returnFilePaths.append(fileName) log.info("Check fail!!") self.ssh.close() self.sftp.close() return returnFilePaths
def checkOneHostFiles(self, filePaths, hostName, userName, hostsPassword, gatewayHosts=None, numberTrials=1, forceOperation = False, operationId=1): """ Check if file paths exists. filepaths -- List of file paths to check with this format: ["absolute_file_path1","absolute_file_path2"] gatewayHosts -- Gateway hosts dictionary with this format: "userName1@hostName1:userName2@hostName2":"userName@hostName" hostsPasswords -- Passwords needed to connect to involved hosts with this format: "userName@hostName":"hostPassword" numberTrials -- Number of trials in error cases. forceOperation -- Flag to indicate if, when an error happens and number of trials is exceeded, the operation must continue with the rest of files. operationId -- Operation identifier. returns -- List of not located file paths. """ returnFilePaths = [] print("**************************************** CHECKING******************************************") log.info("Connecting to: " + userName + "@" + hostName) self.ssh.connect(hostName, SSH_PORT, userName, hostsPassword) self.sftp = self.ssh.open_sftp() isLocalHost = self.__isLocalHost(hostName) for fileName in filePaths: log.info("Checking: " + fileName) if (isLocalHost): if (len (missingPaths(fileName)) != 0): returnFilePaths.append(fileName) log.info("Check fail!!") else: try: self.sftp.lstat(fileName) except IOError: returnFilePaths.append(fileName) log.info("Check fail!!") self.ssh.close() self.sftp.close() return returnFilePaths