Пример #1
0
    def createAllArtifacts(self):
        """
        Creates a list of all the commands the frontend must run in order to copy the specified files
        on the backend(s).
        """
        
        commandList = [] # List of command to execute
        for machine in self.machineHeaderDict.keys(): # For every machines with matching bulletins
            try:
                filelogname = "%sfilelogs/filelog.%s" % (PXPaths.SEARCH, machine)
                filelog = open(filelogname, "w") # This file will need to be transfered to the remote machibe
                self.addToFileList(filelogname)        
            except IOError:
                sys.exit("Could not open filelog for writing!")

            destinations = " ".join(self.destinations)
            bulletins = self.machineHeaderDict[machine]

            # Does the user want to be prompted for every bulletin files
            prompt = self.getPrompt() 
            for bulletin in bulletins:
                if prompt == True:
                    decision = self.getDecision(bulletin, machine, destinations)
                    if decision == True:
                        filelog.write("%s\n" % (searchResendUtils.headerToLocation(bulletin)))
                    else:
                        self.setHeaderCount(self.getHeaderCount() - 1)
                else:
                    filelog.write("%s\n" % (searchResendUtils.headerToLocation(bulletin)))
                    
            filelog.close()
            commandList += ['ssh %s "%sPXCopy.py -m %s -f %s %s"' % (machine, PXPaths.SEARCH, socket.gethostname(), filelogname, destinations)]
        
        return commandList
Пример #2
0
    def createAllArtifacts(self):
        """
        Creates a list of all the commands the frontend must run in order to copy the specified files
        on the backend(s).
        """

        commandList = []  # List of command to execute
        for machine in self.machineHeaderDict.keys(
        ):  # For every machines with matching bulletins
            try:
                filelogname = "%sfilelogs/filelog.%s" % (PXPaths.SEARCH,
                                                         machine)
                filelog = open(
                    filelogname, "w"
                )  # This file will need to be transfered to the remote machibe
                self.addToFileList(filelogname)
            except IOError:
                sys.exit("Could not open filelog for writing!")

            destinations = " ".join(self.destinations)
            bulletins = self.machineHeaderDict[machine]

            # Does the user want to be prompted for every bulletin files
            prompt = self.getPrompt()
            for bulletin in bulletins:
                if prompt == True:
                    decision = self.getDecision(bulletin, machine,
                                                destinations)
                    if decision == True:
                        filelog.write(
                            "%s\n" %
                            (searchResendUtils.headerToLocation(bulletin)))
                    else:
                        self.setHeaderCount(self.getHeaderCount() - 1)
                else:
                    filelog.write(
                        "%s\n" %
                        (searchResendUtils.headerToLocation(bulletin)))

            filelog.close()
            commandList += [
                'ssh %s "%sPXCopy.py -m %s -f %s %s"' %
                (machine, PXPaths.SEARCH, socket.gethostname(), filelogname,
                 destinations)
            ]

        return commandList
Пример #3
0
def readFromDB(file, host):
    """
    Reads a bulletin file from the database.
    The output is copied to a temporary file on the local machine.
    Arguments:
        host   -> machine that hosts the bulletin file
        dbPath -> path to the bulletin in the database
    Returns: path to the bulletin's copy
    """

    dbPath = searchResendUtils.headerToLocation(file)
    command = "sudo -u %s /usr/bin/ssh %s cat %s" % (user, host, dbPath)
    status, output = commands.getstatusoutput(command)
    if not status:
        return output.replace('\n', '<br>')
    else:
        return ''
Пример #4
0
def readFromDB(file, host):
    """
    Reads a bulletin file from the database.
    The output is copied to a temporary file on the local machine.
    Arguments:
        host   -> machine that hosts the bulletin file
        dbPath -> path to the bulletin in the database
    Returns: path to the bulletin's copy
    """
    
    dbPath = searchResendUtils.headerToLocation(file)
    command = "sudo -u %s /usr/bin/ssh %s cat %s" % (user, host, dbPath)
    status, output = commands.getstatusoutput(command)
    if not status:
        return output.replace('\n', '<br>')
    else:
        return ''