Пример #1
0
    def __init__(self, parser="json", provider="local-file"):
        try:
            if parser == "json":
                _parser = JsonParser()
            else:
                raise

            if provider == "metadata-service":
                self._get_value_for = MetadataService(
                    parser=_parser).get_value_for

            elif provider == "local-file":
                self._get_value_for = LocalFile(parser=_parser).get_value_for

            else:
                raise

            agent_logger.log(
                logging.info,
                "DataHandler registered. Parser: %s, Provider: %s" %
                (parser, provider))

        except Exception, e:
            agent_logger.log(
                logging.error,
                "DataHandler register error, Parser: %s, Provider: %s.\n%s" %
                (parser, provider, e.message))
Пример #2
0
 def _cache_data(self, key, value=None):
     """ [WIP] YET FAKE
     Cache config data state for later comparison and
     only configure on difference with current cached config.
     """
     agent_logger.log(logging.info,
                      "[TBD] Caching data need to implemented.")
     return None
Пример #3
0
 def _cache_data(self, key, value=None):
     """ [WIP] YET FAKE
     Cache config data state for later comparison and
     only configure on difference with current cached config.
     """
     agent_logger.log(logging.info,
                      "[TBD] Caching data need to implemented.")
     return None
def run_command(cmd_name):
    try:
        if not cmd_name in commands.cmd_list.keys():
            raise
        return commands.run(cmd_name)

    except:
        agent_logger.log(logging.error,
                         "%s is not a registered command to run." % cmd_name)
        return None
def run_command(cmd_name):
    try:
        if not cmd_name in commands.cmd_list.keys():
            raise
        return commands.run(cmd_name)

    except:
        agent_logger.log(logging.error,
                     "%s is not a registered command to run." % cmd_name)
        return None
Пример #6
0
    def get_value_for(self, key):
        """
        Fetch value from provider, cache and return if it's new
        else return None to indicate no action required.
        """
        try:
            value = self._get_value_for(key)
            cached_value = self._cache_data(key)
            if value == cached_value:
                return None
            self._cache_data(key, value)
            return value

        except Exception, e:
            agent_logger.log(logging.error, "Exception in value for %s: %s" %
                             (key, e.message))
            return None
Пример #7
0
    def get_value_for(self, key):
        """
        Fetch value from provider, cache and return if it's new
        else return None to indicate no action required.
        """
        try:
            value = self._get_value_for(key)
            cached_value = self._cache_data(key)
            if value == cached_value:
                return None
            self._cache_data(key, value)
            return value

        except Exception, e:
            agent_logger.log(
                logging.error,
                "Exception in value for %s: %s" % (key, e.message))
            return None
Пример #8
0
    def __init__(self, parser="json", provider="local-file"):
        try:
            if parser == "json":
                _parser = JsonParser()
            else:
                raise

            if provider == "metadata-service":
                self._get_value_for = MetadataService(parser=_parser).get_value_for

            elif provider == "local-file":
                self._get_value_for = LocalFile(parser=_parser).get_value_for

            else:
                raise

            agent_logger.log(logging.info,
                "DataHandler registered. Parser: %s, Provider: %s" %
                (parser, provider))

        except Exception, e:
            agent_logger.log(logging.error,
                "DataHandler register error, Parser: %s, Provider: %s.\n%s" %
                (parser, provider, e.message))
Пример #9
0
def run(cmd, get_value_for):
    try:
        data_keys = cmd_list[cmd]["data_keys"]
        data_values = {}
        for _data_key in data_keys:
            data_values[_data_key] = get_value_for(_data_key)
        agent_logger.log(logging.info, ">>>> %s" % repr(data_keys))
        agent_logger.log(logging.info, ">>>> %s" % repr(data_values))

        config_result = cmd_list[cmd]["func"](data_values)

        agent_logger.log(logging.info, "Running '%s'" % cmd,
                         data=data_values, result=config_result)
        return config_result

    except Exception, e:
        agent_logger.log(logging.error, e.message)
        return None
Пример #10
0
def run(cmd, get_value_for):
    try:
        data_keys = cmd_list[cmd]["data_keys"]
        data_values = {}
        for _data_key in data_keys:
            data_values[_data_key] = get_value_for(_data_key)
        agent_logger.log(logging.info, ">>>> %s" % repr(data_keys))
        agent_logger.log(logging.info, ">>>> %s" % repr(data_values))

        config_result = cmd_list[cmd]["func"](data_values)

        agent_logger.log(logging.info,
                         "Running '%s'" % cmd,
                         data=data_values,
                         result=config_result)
        return config_result

    except Exception, e:
        agent_logger.log(logging.error, e.message)
        return None
Пример #11
0
    def wrap(_func):
        agent_logger.log(logging.error, str(data_keys))
        if cmd_name in cmd_list.keys():
            agent_logger.log(
                logging.error,
                "%s already exists in feature list. Duplicacy." % cmd_name)

        else:
            _data_keys = data_keys
            if isinstance(_data_keys, str):
                _data_keys = _data_keys.split()
            with open("/tmp/pylog", "a") as fyl:
                fyl.write(repr(_data_keys))

            cmd_list[cmd_name] = {"func": _func, "data_keys": _data_keys}

            agent_logger.log(
                logging.info, "%s added to feature list with keys: %s." %
                (cmd_name, _data_keys))

        return _func
Пример #12
0
    def wrap(_func):
        agent_logger.log(logging.error, str(data_keys))
        if cmd_name in cmd_list.keys():
            agent_logger.log(logging.error,
                         "%s already exists in feature list. Duplicacy." %
                             cmd_name)

        else:
            _data_keys = data_keys
            if isinstance(_data_keys, str):
                _data_keys = _data_keys.split()
            with open("/tmp/pylog", "a") as fyl:
                fyl.write(repr(_data_keys))

            cmd_list[cmd_name] = {"func": _func,
                                  "data_keys": _data_keys}

            agent_logger.log(logging.info,
                             "%s added to feature list with keys: %s." %
                             (cmd_name, _data_keys))

        return _func