Exemplo n.º 1
0
 def buildTasks(self, configDir):
     tc = taskController(configDir, self)
     # Get active tasks list
     tc.tasks = tc.getActiveTasks(walkDir(configDir, 'ini'))
     tc.depTree = tc.buildDependencyTree(tc.tasks)
     tc.prepareEvents(tc.tasks)
     return tc
Exemplo n.º 2
0
 def test_init(self):
     self.appConfigure()
     tasksDir = self.app.appDir + os.sep + "tasks"
     tc = taskController(tasksDir)
     tc.tasks = tc.getActiveTasks(walkDir(tasksDir))
     tc.buildDependencyTree(tc.tasks)
     tc.prepareEvents(tc.tasks)
Exemplo n.º 3
0
    def run(self):
        super(deployTask, self).run()
        source = self.getConfigParam('task.deploy.source')
        destination = self.getConfigParam('task.deploy.destination')
        # Get list of source
        sourceList = walkDir(source)
        # Get list of destination
        if not os.path.exists(destination):
            os.makedirs(destination)
        destinationList = walkDir(destination)
        print source, destination
        # Hash source list
        # Hash destination list
        # Compare source and destination hashes
        # if not match, add source to deploy list
        deployList = {}
        for itemName, itemPath in sourceList.iteritems():
            if itemName in destinationList:
                itemObj = open(itemPath, 'r')
                itemData = itemObj.read()
                itemObj.close()
                sourceHash = hashlib.md5(itemData).digest()

                destItemPath = destinationList[itemName]
                destItemObj = open(destItemPath, 'r')
                destItemData = destItemObj.read()
                destItemObj.close()
                destinationHash = hashlib.md5(destItemData).digest()

                if sourceHash != destinationHash:
                    deployList.update({itemName: itemPath, })
            else:
                deployList.update({itemName: itemPath, })
        print deployList
        if len(deployList) > 0:
            shutil.rmtree(destination)
            shutil.copytree(source, destination)
Exemplo n.º 4
0
    def buildConfig(self, net, ip):
        """
        Build config.
        """
        hostIp = '%s.%s' % (net, ip, )
        self.groupList = []

        self.hostIp = hostIp
        self.groupList.append(hostIp)
        files = walkDir(self.configDir, 'ini')
        for item in files:
            if item == hostIp:
                self.hostConfig = files[item]
                self.getGroupsByPath(self.hostConfig, item)

        self.walkConfigs(self.configDir, 'ini')
Exemplo n.º 5
0
    def buildHostConfig(self, net, ip):
        """
        Build Host Config
        """
        # TODO: do with 4 or 3 octet too.
        hostIp = '%s.%s' % (net, ip, )
        self.groupList = []

        self.hostIp = hostIp
        #self.groupList.append(hostIp)
        files = walkDir(self.configDir, 'ini')
        hostGroupList = []
        for item in files:
            #if item == hostIp:
            if self.isIPMatch(item):
                self.hostConfig = files[item]
                hostGroupList.append(self.getGroupsByPath(self.hostConfig, item))

        if 'hostConfig' not in self.__dict__:
            hostConfig = self.configDir + os.sep + 'hostConfig.ini'
            if os.path.exists(hostConfig):
                # Found an optional host config file for
                # exclude or include hosts or groups
                self.hostConfig = hostConfig

        if 'hostConfig' not in self.__dict__:
            hostConfig = self.workDir + os.sep + 'host.ini'
            if os.path.exists(hostConfig):
                # TODO: Check for match exclude or include hosts or groups
                # Found a host manual pre-defined config file
                self.hostConfig = hostConfig

        if 'hostConfig' not in self.__dict__:
            hostConfig = self.configDir + os.sep + 'defaultHostConfig.ini'
            if os.path.exists(hostConfig):
                # Found a default host config file - last chance
                self.hostConfig = hostConfig

        isMatched = False
        if 'hostConfig' in self.__dict__:
            groupPath = ''
            for group in hostGroupList:
                groupPath += group
                configFile = str(os.sep).join([self.configDir, groupPath, '%s.ini' % (group, ), ])
                self.merge(ConfigObj(configFile))

            self.merge(ConfigObj(self.hostConfig))
            isMatched = True

        self.hostGroupList = hostGroupList
        if 'host' in self.config:
            if 'groups' in self.config['host']:
                groups = self.config['host']['groups']
                for group in groups:

                    groupPart = groups[group].split('.')
                    partLen = len(groupPart)
                    while partLen != 0:
                        part = '.'.join(groupPart[:partLen])
                        if part in self.hostGroupList:
                            partLen -= 1
                            continue
                        self.hostGroupList.append(part)
                        partLen -= 1

                    if groups[group] in self.hostGroupList:
                        continue
                    self.hostGroupList.append(groups[group])
            isMatched = self.isMatched()

        return isMatched