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(instance=instance).items()<EOL><DEDENT>return uptime_table_lookup[instance]<EOL><DEDENT>def _get_bgp_neighbors_core(neighbor_data, instance=None, uptime_table_items=None):<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>{elem[<NUM_LIT:0>]: elem[<NUM_LIT:1>] for elem in bgp_neighbor[<NUM_LIT:1>] if elem[<NUM_LIT:1>] is not None}<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]['<STR_LIT>'] =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(neighbor_details)<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>if neighbor not in bgp_neighbor_data[instance_name]['<STR_LIT>']:<EOL><INDENT>bgp_neighbor_data[instance_name]['<STR_LIT>'][neighbor] = {}<EOL><DEDENT>bgp_neighbor_data[instance_name]['<STR_LIT>'][neighbor]['<STR_LIT>'] = 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(instance_neighbors,<EOL>instance=instance,<EOL>uptime_table_items=uptime_table_items)<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.