def bgp_summary_parser(bgp_summary):
bgp_summary_dict = {}<EOL>if len(bgp_summary.strip().splitlines()) <= <NUM_LIT:1>:<EOL><INDENT>return {}<EOL><DEDENT>allowed_afi = ['<STR_LIT>', '<STR_LIT>']<EOL>vrf_regex = r"<STR_LIT>"<EOL>afi_regex = r"<STR_LIT>"<EOL>local_router_regex = (r"<STR_LIT>"<EOL>r"<STR_LIT>")<EOL>for pattern in [vrf_regex, afi_regex, local_router_regex]:<EOL><INDENT>match = re.search(pattern, bgp_summary, flags=re.M)<EOL>if match:<EOL><INDENT>bgp_summary_dict.update(match.groupdict(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>vrf = bgp_summary_dict['<STR_LIT>']<EOL>if vrf.lower() == '<STR_LIT:default>':<EOL><INDENT>bgp_summary_dict['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>afi = bgp_summary_dict['<STR_LIT>']<EOL>afi = afi.split()[<NUM_LIT:0>].lower()<EOL>if afi not in allowed_afi:<EOL><INDENT>raise ValueError("<STR_LIT>".format(afi))<EOL><DEDENT>bgp_summary_dict['<STR_LIT>'] = afi<EOL>local_as = bgp_summary_dict['<STR_LIT>']<EOL>local_as = napalm_base.helpers.as_number(local_as)<EOL>match = re.search(IPV4_ADDR_REGEX, bgp_summary_dict['<STR_LIT>'])<EOL>if not match:<EOL><INDENT>raise ValueError("<STR_LIT>".format(bgp_summary_dict['<STR_LIT>']))<EOL><DEDENT>vrf = bgp_summary_dict['<STR_LIT>']<EOL>bgp_return_dict = {<EOL>vrf: {<EOL>"<STR_LIT>": bgp_summary_dict['<STR_LIT>'],<EOL>"<STR_LIT>": {},<EOL>}<EOL>}<EOL>tabular_divider = r"<STR_LIT>"<EOL>tabular_data = re.split(tabular_divider, bgp_summary, flags=re.M)<EOL>if len(tabular_data) != <NUM_LIT:2>:<EOL><INDENT>msg = "<STR_LIT>".format(bgp_summary)<EOL>raise ValueError(msg)<EOL><DEDENT>tabular_data = tabular_data[<NUM_LIT:1>]<EOL>bgp_table = bgp_normalize_table_data(tabular_data)<EOL>for bgp_entry in bgp_table_parser(bgp_table):<EOL><INDENT>bgp_return_dict[vrf]["<STR_LIT>"].update(bgp_entry)<EOL><DEDENT>bgp_new_dict = {}<EOL>for neighbor, bgp_data in bgp_return_dict[vrf]["<STR_LIT>"].items():<EOL><INDENT>received_prefixes = bgp_data.pop("<STR_LIT>")<EOL>bgp_data["<STR_LIT>"] = {}<EOL>prefixes_dict = {"<STR_LIT>": -<NUM_LIT:1>,<EOL>"<STR_LIT>": -<NUM_LIT:1>,<EOL>"<STR_LIT>": received_prefixes}<EOL>bgp_data["<STR_LIT>"][afi] = prefixes_dict<EOL>bgp_data["<STR_LIT>"] = local_as<EOL>bgp_data["<STR_LIT>"] = "<STR_LIT>"<EOL>bgp_new_dict[neighbor] = bgp_data<EOL><DEDENT>bgp_return_dict[vrf]["<STR_LIT>"] = bgp_new_dict<EOL>return bgp_return_dict<EOL>
Parse 'show bgp all summary vrf' output information from NX-OS devices.