def _config_file_get_server_files(self, applicationGroup):
        ''' Function that gets the configuration file for diffing or runs the remote command and saves the output to a file.
        '''
        # Create the output folder to store the generated files
        serverFilesPath = _utils._setup_output_folders(
            os.path.join(GLOBAL_VARIABLES['${OUTPUTDIR}'],
                         "serverFiles_%s" % self.environment,
                         applicationGroup))
        if not os.path.exists(serverFilesPath):
            os.makedirs(serverFilesPath)

        for configFile in self.environmentData['applicationGroups'][
                applicationGroup]['configurationFiles']:
            for server in self.environmentData['applicationGroups'][
                    applicationGroup]['servers']:

                # Creates the connection to the remote server
                self.robotBuiltIn.run_keyword("Open Connection", server)
                returnValues = self.robotBuiltIn.run_keyword(
                    "RSA Get Key Locations")
                self.robotBuiltIn.run_keyword(
                    "Login With Public Key",
                    self.environmentData['environment']['auditUsername'],
                    returnValues['privateKey'].replace("/", "\\\\").replace(
                        "\\", "\\\\"), returnValues['privateKeyPass'].replace(
                            "/", "\\\\").replace("\\", "\\\\"))

                # Creates the file destination name
                destFileName = os.path.join(serverFilesPath,
                                            (("%s_%s") % (server, configFile)))

                if self.templateData[configFile]['configuration'][
                        'type'] == "file":
                    sourceFileName = self.templateData[configFile][
                        'configuration']['fileLocation']
                    returnResult = self.robotBuiltIn.run_keyword_and_ignore_error(
                        "Get File", sourceFileName,
                        destFileName.replace("\\", "\\\\"))
                    if returnResult[0] == "FAIL":
                        _utils._result_logger(self.resultFile, server,
                                              configFile, "Fail",
                                              sourceFileName)
                        raise Exception(
                            ("There were no files matching %s on server %s") %
                            (sourceFileName, server))

                if self.templateData[configFile]['configuration'][
                        'type'] == "command":
                    cmd = self.templateData[configFile]['configuration'][
                        'command']
                    actualResult = self.robotBuiltIn.run_keyword(
                        'Execute Command', cmd)
                    _utils._write_file(destFileName, actualResult)

                # Disconnect ssh session
                self.robotBuiltIn.run_keyword("Close Connection")

        return serverFilesPath
 def _config_file_build_write(self, generatedFilesPath, configFile, server):
     ''' Writes the generated configuration file to disk.
     '''
     configFileRaw = self.envTemplates.get_template(configFile)
     fileContents = configFileRaw.render(self.configurationFileSettings)
     
     fileContents = fileContents.replace("${ #}", "${#}")
     
     fileLocation = os.path.join(generatedFilesPath, (("%s_%s") % (server, configFile)))
     _utils._write_file(fileLocation, fileContents)
    def _config_file_build_write(self, generatedFilesPath, configFile, server):
        ''' Writes the generated configuration file to disk.
        '''
        configFileRaw = self.envTemplates.get_template(configFile)
        fileContents = configFileRaw.render(self.configurationFileSettings)

        fileContents = fileContents.replace("${ #}", "${#}")

        fileLocation = os.path.join(generatedFilesPath,
                                    (("%s_%s") % (server, configFile)))
        _utils._write_file(fileLocation, fileContents)
    def _config_file_get_server_files(self, applicationGroup):
        ''' Function that gets the configuration file for diffing or runs the remote command and saves the output to a file.
        '''
        # Create the output folder to store the generated files
        serverFilesPath = _utils._setup_output_folders(os.path.join(GLOBAL_VARIABLES['${OUTPUTDIR}'], "serverFiles_%s" % self.environment, applicationGroup))
        if not os.path.exists(serverFilesPath):
            os.makedirs(serverFilesPath)
                    
        for configFile in self.environmentData['applicationGroups'][applicationGroup]['configurationFiles']:
            for server in self.environmentData['applicationGroups'][applicationGroup]['servers']:
                
                # Creates the connection to the remote server
                self.robotBuiltIn.run_keyword("Open Connection", server)
                returnValues = self.robotBuiltIn.run_keyword("RSA Get Key Locations")
                self.robotBuiltIn.run_keyword("Login With Public Key", 
                                              self.environmentData['environment']['auditUsername'],
                                              returnValues['privateKey'].replace("/", "\\\\").replace("\\", "\\\\"),
                                              returnValues['privateKeyPass'].replace("/", "\\\\").replace("\\", "\\\\"))

                # Creates the file destination name
                destFileName = os.path.join(serverFilesPath, (("%s_%s") % (server, configFile)))
                
                if self.templateData[configFile]['configuration']['type'] == "file":
                    sourceFileName =  self.templateData[configFile]['configuration']['fileLocation']                
                    returnResult = self.robotBuiltIn.run_keyword_and_ignore_error("Get File", sourceFileName, destFileName.replace("\\", "\\\\"))
                    if returnResult[0] == "FAIL":
                        _utils._result_logger(self.resultFile, server, configFile, "Fail", sourceFileName)
                        raise Exception (("There were no files matching %s on server %s") % (sourceFileName, server))                
                
                if self.templateData[configFile]['configuration']['type'] == "command":
                    cmd = self.templateData[configFile]['configuration']['command']
                    actualResult = self.robotBuiltIn.run_keyword('Execute Command', cmd)
                    _utils._write_file(destFileName, actualResult)
                
                # Disconnect ssh session
                self.robotBuiltIn.run_keyword("Close Connection")

        return serverFilesPath