def process_store(identity, store): """Parses raw store data and returns contents. Called at startup to initialize the parsed version of the store.""" results = {} name_map = {} sync_store = False for config_name, config_data in store.items(): config_type = config_data["type"] config_string = config_data["data"] try: processed_config = process_raw_config(config_string, config_type) if check_for_recursion(config_name, processed_config, results): raise ValueError("Recursive configuration references") results[config_name] = processed_config except ValueError as e: _log.error("Error processing Agent {} config {}: {}".format(identity, config_name, str(e))) sync_store = True del store[config_name] if config_name.lower() in name_map: _log.error("Conflicting names in store, dropping {}".format(config_name)) sync_store = True del store[config_name] else: name_map[config_name.lower()] = config_name if sync_store: _log.warning("Removing invalid configurations for Agent {}".format(identity)) store.sync() return results, name_map
def process_store(identity, store): """Parses raw store data and returns contents. Called at startup to initialize the parsed version of the store.""" results = {} name_map = {} sync_store = False for config_name, config_data in store.items(): config_type = config_data["type"] config_string = config_data["data"] try: processed_config = process_raw_config(config_string, config_type) if check_for_recursion(config_name, processed_config, results): raise ValueError("Recursive configuration references") results[config_name] = processed_config except ValueError as e: _log.error("Error processing Agent {} config {}: {}".format( identity, config_name, str(e))) sync_store = True del store[config_name] if config_name.lower() in name_map: _log.error( "Conflicting names in store, dropping {}".format(config_name)) sync_store = True del store[config_name] else: name_map[config_name.lower()] = config_name if sync_store: _log.warning( "Removing invalid configurations for Agent {}".format(identity)) store.sync() return results, name_map
def _add_config_to_store(self, identity, config_name, raw, parsed, config_type, trigger_callback=False, send_update=True): """Adds a processed configuration to the store.""" agent_store = self.store.get(identity) action = "UPDATE" if agent_store is None: #Initialize a new store. store_path = os.path.join(self.store_path, identity+ store_ext) store = PersistentDict(filename=store_path, flag='c', format='json') agent_store = {"configs": {}, "store": store, "name_map": {}, "lock": Semaphore()} self.store[identity] = agent_store agent_configs = agent_store["configs"] agent_disk_store = agent_store["store"] agent_store_lock = agent_store["lock"] agent_name_map = agent_store["name_map"] config_name = strip_config_name(config_name) config_name_lower = config_name.lower() if config_name_lower not in agent_name_map: action = "NEW" if check_for_recursion(config_name, parsed, agent_configs): raise ValueError("Recursive configuration references detected.") if config_name_lower in agent_name_map: old_config_name = agent_name_map[config_name_lower] del agent_configs[old_config_name] agent_configs[config_name] = parsed agent_name_map[config_name_lower] = config_name agent_disk_store[config_name] = {"type": config_type, "modified": format_timestamp(get_aware_utc_now()), "data": raw} agent_disk_store.async_sync() _log.debug("Agent {} config {} stored.".format(identity, config_name)) if send_update: with agent_store_lock: try: self.vip.rpc.call(identity, "config.update", action, config_name, contents=parsed, trigger_callback=trigger_callback).get(timeout=10.0) except errors.Unreachable: _log.debug("Agent {} not currently running. Configuration update not sent.".format(identity)) except RemoteError as e: _log.error("Agent {} failure when adding/updating configuration {}: {}".format(identity, config_name, e)) except MethodNotFound as e: _log.error( "Agent {} failure when adding/updating configuration {}: {}".format(identity, config_name, e))