def manage_get_metadata(self, identity, config_name): agent_store = self.store.get(identity) if agent_store is None: raise KeyError( 'No configuration file "{}" for VIP IDENTIY {}'.format( config_name, identity)) agent_disk_store = agent_store["store"] 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: raise KeyError( 'No configuration file "{}" for VIP IDENTIY {}'.format( config_name, identity)) real_config_name = agent_name_map[config_name_lower] real_config = agent_disk_store[real_config_name] #Set modified to none if we predate the modified flag. if real_config.get("modified") is None: real_config["modified"] = None return real_config
def manage_get(self, identity, config_name, raw=True): agent_store = self.store.get(identity) if agent_store is None: raise KeyError( 'No configuration file "{}" for VIP IDENTIY {}'.format( config_name, identity)) agent_configs = agent_store["configs"] agent_disk_store = agent_store["store"] 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: raise KeyError( 'No configuration file "{}" for VIP IDENTIY {}'.format( config_name, identity)) real_config_name = agent_name_map[config_name_lower] if raw: return agent_disk_store[real_config_name]["data"] return agent_configs[real_config_name]
def delete(self, identity, config_name, trigger_callback=False, send_update=True): agent_store = self.store.get(identity) if agent_store is None: raise KeyError( 'No configuration file "{}" for VIP IDENTIY {}'.format( config_name, identity)) 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: raise KeyError( 'No configuration file "{}" for VIP IDENTIY {}'.format( config_name, identity)) real_config_name = agent_name_map[config_name_lower] agent_configs.pop(real_config_name) agent_disk_store.pop(real_config_name) agent_name_map.pop(config_name_lower) # Sync will delete the file if the store is empty. agent_disk_store.async_sync() if send_update: with agent_store_lock: try: self.vip.rpc.call( identity, "config.update", "DELETE", config_name, 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 deleting configuration {}: {}". format(identity, config_name, e)) except MethodNotFound as e: _log.error( "Agent {} failure when adding/updating configuration {}: {}" .format(identity, config_name, e)) # If the store is empty (and nothing jumped in and added to it while we # were informing the agent) then remove it from the global store. if not agent_disk_store: self.store.pop(identity, None)
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))
def delete(self, identity, config_name, trigger_callback=False, send_update=True): agent_store = self.store.get(identity) if agent_store is None: raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity)) 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: raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity)) real_config_name = agent_name_map[config_name_lower] agent_configs.pop(real_config_name) agent_disk_store.pop(real_config_name) agent_name_map.pop(config_name_lower) # Sync will delete the file if the store is empty. agent_disk_store.async_sync() if send_update: with agent_store_lock: try: self.vip.rpc.call(identity, "config.update", "DELETE", config_name, 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 deleting configuration {}: {}".format(identity, config_name, e)) except MethodNotFound as e: _log.error( "Agent {} failure when adding/updating configuration {}: {}".format(identity, config_name, e)) # If the store is empty (and nothing jumped in and added to it while we # were informing the agent) then remove it from the global store. if not agent_disk_store: self.store.pop(identity, None)
def manage_get(self, identity, config_name, raw=True): agent_store = self.store.get(identity) if agent_store is None: raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity)) agent_configs = agent_store["configs"] agent_disk_store = agent_store["store"] 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: raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity)) real_config_name = agent_name_map[config_name_lower] if raw: return agent_disk_store[real_config_name]["data"] return agent_configs[real_config_name]
def manage_get_metadata(self, identity, config_name): agent_store = self.store.get(identity) if agent_store is None: raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity)) agent_disk_store = agent_store["store"] 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: raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity)) real_config_name = agent_name_map[config_name_lower] real_config = agent_disk_store[real_config_name] #Set modified to none if we predate the modified flag. if real_config.get("modified") is None: real_config["modified"] = None return real_config