예제 #1
0
    def run(self):
        """Lunches checks and triggers updates on BIRD configuration."""
        self.log.info("Lunching checks")

        # Lunch a thread for each configuration
        self.log.info("Going to lunch {} threads".format(len(self.services)))
        for service in self.services:
            self.log.debug("Lunching thread for {}".format(service))
            _config = {}
            for option, getter in OPTIONS_TYPE.items():
                _config[option] = getattr(self.config, getter)(service, option)
            _thread = ServiceCheck(
                service,
                _config,
                self.action,
                self.log)
            _thread.start()

        # Stay running until we are stopped
        while True:
            # Fetch items from action queue
            operation = self.action.get(block=True)
            self.log.info(("Returned an item from the queue for {n} with "
                           "IP prefix {i} and action to {o} Bird "
                           "configuration").format(n=operation.name,
                                                   i=operation.ip_prefix,
                                                   o=operation))

            bird_updated = self._update_bird_prefix_conf(operation)
            self.action.task_done()
            if bird_updated:
                self._reload_bird()
예제 #2
0
    def run(self):
        """Lunches checks and triggers updates on BIRD configuration."""
        self.log.info("Lunching checks")
        _workers = []

        # Lunch a thread for each configuration
        self.log.info("Going to lunch {} threads".format(len(self.services)))
        for service in self.services:
            self.log.debug("Lunching thread for {}".format(service))
            _config = {}
            for option, getter in OPTIONS_TYPE.items():
                _config[option] = getattr(self.config, getter)(service, option)
            _thread = ServiceCheck(
                service,
                _config,
                self.action,
                self.log)
            _thread.start()
            _workers.append(_thread)

        # Stay running until we are stopped
        while True:
            try:
                # Fetch items from action queue
                health_action = self.action.get(1)
                self.log.info(("Returned an item from the queue for {} with "
                               "IP prefix {} and action to {} from Bird "
                               "configuration").format(health_action[0],
                                                       health_action[1],
                                                       health_action[2]))

                bird_updated = self._update_bird_prefix_conf(health_action)
                self.action.task_done()
                if bird_updated:
                    self._reload_bird()
            except Empty:
                # Just keep trying to fetch items
                continue

        for _thread in _workers:
            _thread.join()