def get_bgp_neighbors(self):
bgp_neighbor_data = {}<EOL>default_neighbor_details = {<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": False,<EOL>"<STR_LIT>": False,<EOL>"<STR_LIT:description>": "<STR_LIT>",<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": {},<EOL>}<EOL>keys = default_neighbor_details.keys()<EOL>uptime_table = junos_views.junos_bgp_uptime_table(self.device)<EOL>bgp_neighbors_table = junos_views.junos_bgp_table(self.device)<EOL>uptime_table_lookup = {}<EOL>def _get_uptime_table(instance):<EOL><INDENT>if instance not in uptime_table_lookup:<EOL><INDENT>uptime_table_lookup[instance] = uptime_table.get(<EOL>instance=instance<EOL>).items()<EOL><DEDENT>return uptime_table_lookup[instance]<EOL><DEDENT>def _get_bgp_neighbors_core(<EOL>neighbor_data, instance=None, uptime_table_items=None<EOL>):<EOL><INDENT>"""<STR_LIT>"""<EOL>for bgp_neighbor in neighbor_data:<EOL><INDENT>peer_ip = napalm.base.helpers.ip(bgp_neighbor[<NUM_LIT:0>].split("<STR_LIT:+>")[<NUM_LIT:0>])<EOL>neighbor_details = deepcopy(default_neighbor_details)<EOL>neighbor_details.update(<EOL>{<EOL>elem[<NUM_LIT:0>]: elem[<NUM_LIT:1>]<EOL>for elem in bgp_neighbor[<NUM_LIT:1>]<EOL>if elem[<NUM_LIT:1>] is not None<EOL>}<EOL>)<EOL>if not instance:<EOL><INDENT>peer_fwd_rti = neighbor_details.pop("<STR_LIT>")<EOL>instance = peer_fwd_rti<EOL><DEDENT>else:<EOL><INDENT>peer_fwd_rti = neighbor_details.pop("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>instance_name = "<STR_LIT>" if instance == "<STR_LIT>" else instance<EOL>if instance_name not in bgp_neighbor_data:<EOL><INDENT>bgp_neighbor_data[instance_name] = {}<EOL><DEDENT>if "<STR_LIT>" not in bgp_neighbor_data[instance_name]:<EOL><INDENT>bgp_neighbor_data[instance_name][<EOL>"<STR_LIT>"<EOL>] = py23_compat.text_type(neighbor_details.get("<STR_LIT>", "<STR_LIT>"))<EOL><DEDENT>peer = {<EOL>key: self._parse_value(value)<EOL>for key, value in neighbor_details.items()<EOL>if key in keys<EOL>}<EOL>peer["<STR_LIT>"] = napalm.base.helpers.as_number(peer["<STR_LIT>"])<EOL>peer["<STR_LIT>"] = napalm.base.helpers.as_number(peer["<STR_LIT>"])<EOL>peer["<STR_LIT>"] = self._parse_route_stats(<EOL>neighbor_details, instance<EOL>)<EOL>if "<STR_LIT>" not in bgp_neighbor_data[instance_name]:<EOL><INDENT>bgp_neighbor_data[instance_name]["<STR_LIT>"] = {}<EOL><DEDENT>bgp_neighbor_data[instance_name]["<STR_LIT>"][peer_ip] = peer<EOL>if not uptime_table_items:<EOL><INDENT>uptime_table_items = _get_uptime_table(instance)<EOL><DEDENT>for neighbor, uptime in uptime_table_items:<EOL><INDENT>normalized_neighbor = napalm.base.helpers.ip(neighbor)<EOL>if (<EOL>normalized_neighbor<EOL>not in bgp_neighbor_data[instance_name]["<STR_LIT>"]<EOL>):<EOL><INDENT>bgp_neighbor_data[instance_name]["<STR_LIT>"][<EOL>normalized_neighbor<EOL>] = {}<EOL><DEDENT>bgp_neighbor_data[instance_name]["<STR_LIT>"][normalized_neighbor][<EOL>"<STR_LIT>"<EOL>] = uptime[<NUM_LIT:0>][<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT>instances = junos_views.junos_route_instance_table(self.device).get()<EOL>for instance, instance_data in instances.items():<EOL><INDENT>if instance.startswith("<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>bgp_neighbor_data[instance] = {"<STR_LIT>": {}}<EOL>instance_neighbors = bgp_neighbors_table.get(instance=instance).items()<EOL>uptime_table_items = uptime_table.get(instance=instance).items()<EOL>_get_bgp_neighbors_core(<EOL>instance_neighbors,<EOL>instance=instance,<EOL>uptime_table_items=uptime_table_items,<EOL>)<EOL><DEDENT>bgp_tmp_dict = {}<EOL>for k, v in bgp_neighbor_data.items():<EOL><INDENT>if bgp_neighbor_data[k]["<STR_LIT>"]:<EOL><INDENT>bgp_tmp_dict[k] = v<EOL><DEDENT><DEDENT>return bgp_tmp_dict<EOL>
Return BGP neighbors details.