def get_config(module, flags): """Retrieves the current config from the device or cache """ flags = [] if flags is None else flags if isinstance(flags, str): flags = [flags] elif not isinstance(flags, list): flags = [] cmd = 'display current-configuration ' cmd += ' '.join(flags) cmd = cmd.strip() conn = get_connection(module) rc, out, err = conn.exec_command(cmd) if rc != 0: module.fail_json(msg=err) cfg = str(out).strip() # remove default configuration prefix '~' for flag in flags: if "include-default" in flag: cfg = rm_config_prefix(cfg) break if cfg.startswith('display'): lines = cfg.split('\n') if len(lines) > 1: return '\n'.join(lines[1:]) else: return '' return cfg
def get_config(module, flags): """Retrieves the current config from the device or cache """ time_stamp_regex = re.compile( r'\s*\d{4}-\d{1,2}-\d{1,2}\s+\d{2}\:\d{2}\:\d{2}\.\d+\s*') flags = [] if flags is None else flags if isinstance(flags, str): flags = [flags] elif not isinstance(flags, list): flags = [] cmd = 'display current-configuration ' cmd += ' '.join(flags) cmd = cmd.strip() conn = get_connection(module) rc, out, err = conn.exec_command(cmd) if rc != 0: module.fail_json(msg=err) cfg = str(out).strip() # remove default configuration prefix '~' for flag in flags: if "include-default" in flag: cfg = rm_config_prefix(cfg) break lines = cfg.split('\n') lines = [l for l in lines if time_stamp_regex.match(l) is None] if cfg.startswith('display'): if len(lines) > 1: lines.pop(0) else: return '' return '\n'.join(lines)