def get_bgp_neighbors_detail(self, neighbor_address="<STR_LIT>"):
def _parse_per_peer_bgp_detail(peer_output):<EOL><INDENT>"""<STR_LIT>"""<EOL>int_fields = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>]<EOL>peer_details = []<EOL>peer_info = napalm.base.helpers.textfsm_extractor(<EOL>self, "<STR_LIT>", peer_output<EOL>)<EOL>for item in peer_info:<EOL><INDENT>item["<STR_LIT>"] = True if item["<STR_LIT>"] == "<STR_LIT>" else False<EOL>item["<STR_LIT>"] = (<EOL>True if item["<STR_LIT>"] else False<EOL>)<EOL>item["<STR_LIT>"] = (<EOL>False if item["<STR_LIT>"] == <NUM_LIT:0> or item["<STR_LIT>"] == "<STR_LIT>" else True<EOL>)<EOL>item["<STR_LIT>"] = False<EOL>item["<STR_LIT>"] = False<EOL>item["<STR_LIT>"] = False<EOL>item["<STR_LIT>"] = False<EOL>item["<STR_LIT>"] = <NUM_LIT:0><EOL>item["<STR_LIT>"] = <NUM_LIT:0><EOL>item["<STR_LIT>"] = <NUM_LIT:0><EOL>for key in int_fields:<EOL><INDENT>item[key] = napalm.base.helpers.convert(int, item[key], <NUM_LIT:0>)<EOL><DEDENT>item["<STR_LIT>"] = napalm.base.helpers.convert(<EOL>py23_compat.text_type, item["<STR_LIT>"]<EOL>)<EOL>item["<STR_LIT>"] = napalm.base.helpers.convert(<EOL>py23_compat.text_type, item["<STR_LIT>"]<EOL>)<EOL>item["<STR_LIT>"] = napalm.base.helpers.ip(item["<STR_LIT>"])<EOL>item["<STR_LIT>"] = napalm.base.helpers.convert(<EOL>py23_compat.text_type, item["<STR_LIT>"]<EOL>)<EOL>item["<STR_LIT>"] = napalm.base.helpers.convert(<EOL>py23_compat.text_type, item["<STR_LIT>"]<EOL>)<EOL>item["<STR_LIT>"] = napalm.base.helpers.convert(<EOL>py23_compat.text_type, item["<STR_LIT>"]<EOL>)<EOL>item["<STR_LIT>"] = napalm.base.helpers.convert(<EOL>py23_compat.text_type, item["<STR_LIT>"]<EOL>)<EOL>item["<STR_LIT>"] = napalm.base.helpers.ip(item["<STR_LIT>"])<EOL>item["<STR_LIT>"] = napalm.base.helpers.convert(<EOL>napalm.base.helpers.ip, item["<STR_LIT>"]<EOL>)<EOL>peer_details.append(item)<EOL><DEDENT>return peer_details<EOL><DEDENT>def _append(bgp_dict, peer_info):<EOL><INDENT>remote_as = peer_info["<STR_LIT>"]<EOL>vrf_name = peer_info["<STR_LIT>"]<EOL>if vrf_name not in bgp_dict.keys():<EOL><INDENT>bgp_dict[vrf_name] = {}<EOL><DEDENT>if remote_as not in bgp_dict[vrf_name].keys():<EOL><INDENT>bgp_dict[vrf_name][remote_as] = []<EOL><DEDENT>bgp_dict[vrf_name][remote_as].append(peer_info)<EOL><DEDENT>commands = []<EOL>summary_commands = []<EOL>if not neighbor_address:<EOL><INDENT>commands.append("<STR_LIT>")<EOL>commands.append("<STR_LIT>")<EOL>summary_commands.append("<STR_LIT>")<EOL>summary_commands.append("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>peer_ver = IPAddress(neighbor_address).version<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise e<EOL><DEDENT>if peer_ver == <NUM_LIT:4>:<EOL><INDENT>commands.append("<STR_LIT>" % neighbor_address)<EOL>summary_commands.append("<STR_LIT>")<EOL><DEDENT>elif peer_ver == <NUM_LIT:6>:<EOL><INDENT>commands.append("<STR_LIT>" % neighbor_address)<EOL>summary_commands.append("<STR_LIT>")<EOL><DEDENT><DEDENT>raw_output = self.device.run_commands(commands, encoding="<STR_LIT:text>")<EOL>bgp_summary = self.device.run_commands(summary_commands, encoding="<STR_LIT>")<EOL>bgp_detail_info = {}<EOL>v4_peer_info = []<EOL>v6_peer_info = []<EOL>if neighbor_address:<EOL><INDENT>peer_info = _parse_per_peer_bgp_detail(raw_output[<NUM_LIT:0>]["<STR_LIT>"])<EOL>if peer_ver == <NUM_LIT:4>:<EOL><INDENT>v4_peer_info.append(peer_info[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>v6_peer_info.append(peer_info[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>v4_peer_info = _parse_per_peer_bgp_detail(raw_output[<NUM_LIT:0>]["<STR_LIT>"])<EOL>v6_peer_info = _parse_per_peer_bgp_detail(raw_output[<NUM_LIT:1>]["<STR_LIT>"])<EOL><DEDENT>for peer_info in v4_peer_info:<EOL><INDENT>vrf_name = peer_info["<STR_LIT>"]<EOL>peer_remote_addr = peer_info["<STR_LIT>"]<EOL>peer_info["<STR_LIT>"] = (<EOL>bgp_summary[<NUM_LIT:0>]["<STR_LIT>"][vrf_name]["<STR_LIT>"][peer_remote_addr][<EOL>"<STR_LIT>"<EOL>]<EOL>if peer_remote_addr in bgp_summary[<NUM_LIT:0>]["<STR_LIT>"][vrf_name]["<STR_LIT>"].keys()<EOL>else <NUM_LIT:0><EOL>)<EOL>_append(bgp_detail_info, peer_info)<EOL><DEDENT>for peer_info in v6_peer_info:<EOL><INDENT>vrf_name = peer_info["<STR_LIT>"]<EOL>peer_remote_addr = peer_info["<STR_LIT>"]<EOL>peer_info["<STR_LIT>"] = (<EOL>bgp_summary[<NUM_LIT:1>]["<STR_LIT>"][vrf_name]["<STR_LIT>"][peer_remote_addr][<EOL>"<STR_LIT>"<EOL>]<EOL>if peer_remote_addr in bgp_summary[<NUM_LIT:1>]["<STR_LIT>"][vrf_name]["<STR_LIT>"].keys()<EOL>else <NUM_LIT:0><EOL>)<EOL>_append(bgp_detail_info, peer_info)<EOL><DEDENT>return bgp_detail_info<EOL>
Implementation of get_bgp_neighbors_detail