Beispiel #1
0
    def create_agents(self):
        """
        Prepares the vSphere Agents used by the vPoller Worker

        Raises:
            VPollerException

        """
        logger.debug('Creating vSphere Agents')

        db = VConnectorDatabase(self.config.get('db'))
        agents = db.get_agents(only_enabled=True)

        if not agents:
            logger.warning('No registered or enabled vSphere Agents found')
            raise VPollerException(
                'No registered or enabled vSphere Agents found')

        for agent in agents:
            a = VConnector(
                user=agent['user'],
                pwd=agent['pwd'],
                host=agent['host'],
                cache_enabled=self.config.get('cache_enabled'),
                cache_maxsize=self.config.get('cache_maxsize'),
                cache_ttl=self.config.get('cache_ttl'),
                cache_housekeeping=self.config.get('cache_housekeeping'))
            self.agents[a.host] = a
            logger.info('Created vSphere Agent for %s', agent['host'])
Beispiel #2
0
    def __init__(self, name, function, required=None):
        if not callable(function):
            raise VPollerException('Task %s is not callable', name)

        self.name = name
        self.function = function
        self.required = required
Beispiel #3
0
    def load_task_modules(self):
        """
        Loads the task modules

        """
        if not self.config.get('tasks'):
            raise VPollerException('No task modules provided')

        for task in self.config.get('tasks'):
            task = task.strip()
            logger.info('Loading task module %s', task)
            try:
                module = importlib.import_module(task)
            except ImportError as e:
                logger.warning('Cannot import task module: %s', e.message)
                continue
            self.task_modules[task] = module

        if not self.task_modules:
            raise VPollerException('No task modules loaded')
Beispiel #4
0
    def register(self, task):
        """
        Register a new task

        Args:
            task (Task): A Task instance to be registered

        """
        if not isinstance(task, Task):
            raise VPollerException('The task should be an instance of Task class')

        self._registry[task.name] = task