def _expaner_os() -> Callable[[str], str]: config = get_config() cfg_map = config.maps["interfaces"] mapper = re.compile(r"|".join(list(cfg_map))) def _expander(ifname): return mapper.sub(lambda mo: cfg_map[mo.group(0)], ifname) return _expander
def get_collection(source: Source, name: str) -> Collection: cfg = get_config() if name not in cfg.collections: msg = f"Collection '{name}' not found in nauti configuration file." get_logger().error(msg) raise RuntimeError(msg) if ( cls := next( ( cls for cls in Collection.__subclasses__() if cls.name == name and cls.source_class.name == source.name ), None, ) ) is None: raise RuntimeError(f"ERROR:NOT-FOUND: nauti collection: {source.name}/{name}")
def get_source(name: str, **kwargs) -> Source: """ Return the Source class designated by the 'name' field. If a source by `name` is not found, then raise RuntimeError. Parameters ---------- name: str The name of the source type, for example "netbox" or "ipfabric". """ source_cls = next( (cls for cls in Source.__subclasses__() if cls.name == name), None ) if not source_cls: raise RuntimeError(f"ERROR:NOT-FOUND: nauti source: {name}") cfg = get_config() src_cfg = cfg.sources[name] src_inst_cfg = src_cfg.copy() return source_cls(config=src_inst_cfg, **kwargs)
def domain_remover(): cfg_obj = get_config() any_domain = "|".join(re.escape(f".{domain}") for domain in cfg_obj.domain_names) return partial(re.compile(any_domain).sub, repl="")
def domain_remover(): cfg_obj = get_config() any_domain = "|".join( map(re.escape, map(partial(concat, "."), cfg_obj.domain_names))) return partial(re.compile(any_domain).sub, repl="")