def get_bgp_config(self, group='<STR_LIT>', neighbor='<STR_LIT>'):
def update_dict(d, u):  <EOL><INDENT>for k, v in u.items():<EOL><INDENT>if isinstance(d, collections.Mapping):<EOL><INDENT>if isinstance(v, collections.Mapping):<EOL><INDENT>r = update_dict(d.get(k, {}), v)<EOL>d[k] = r<EOL><DEDENT>else:<EOL><INDENT>d[k] = u[k]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>d = {k: u[k]}<EOL><DEDENT><DEDENT>return d<EOL><DEDENT>def build_prefix_limit(**args):<EOL><INDENT>"""<STR_LIT>"""<EOL>prefix_limit = {}<EOL>for key, value in args.items():<EOL><INDENT>key_levels = key.split('<STR_LIT:_>')<EOL>length = len(key_levels)-<NUM_LIT:1><EOL>temp_dict = {<EOL>key_levels[length]: value<EOL>}<EOL>for index in reversed(range(length)):<EOL><INDENT>level = key_levels[index]<EOL>temp_dict = {level: temp_dict}<EOL><DEDENT>update_dict(prefix_limit, temp_dict)<EOL><DEDENT>return prefix_limit<EOL><DEDENT>_COMMON_FIELDS_DATATYPE_ = {<EOL>'<STR_LIT:description>': py23_compat.text_type,<EOL>'<STR_LIT>': py23_compat.text_type,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': py23_compat.text_type,<EOL>'<STR_LIT>': py23_compat.text_type,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': py23_compat.text_type,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': int,<EOL>'<STR_LIT>': py23_compat.text_type,<EOL>}<EOL>_PEER_FIELDS_DATATYPE_MAP_ = {<EOL>'<STR_LIT>': py23_compat.text_type,<EOL>'<STR_LIT>': bool,<EOL>'<STR_LIT>': bool<EOL>}<EOL>_PEER_FIELDS_DATATYPE_MAP_.update(<EOL>_COMMON_FIELDS_DATATYPE_<EOL>)<EOL>_GROUP_FIELDS_DATATYPE_MAP_ = {<EOL>'<STR_LIT:type>': py23_compat.text_type,<EOL>'<STR_LIT>': list,<EOL>'<STR_LIT>': bool,<EOL>'<STR_LIT>': bool,<EOL>'<STR_LIT>': int<EOL>}<EOL>_GROUP_FIELDS_DATATYPE_MAP_.update(<EOL>_COMMON_FIELDS_DATATYPE_<EOL>)<EOL>_DATATYPE_DEFAULT_ = {<EOL>py23_compat.text_type: '<STR_LIT>',<EOL>int: <NUM_LIT:0>,<EOL>bool: False,<EOL>list: []<EOL>}<EOL>bgp_config = {}<EOL>if group:<EOL><INDENT>bgp = junos_views.junos_bgp_config_group_table(self.device)<EOL>bgp.get(group=group)<EOL><DEDENT>else:<EOL><INDENT>bgp = junos_views.junos_bgp_config_table(self.device)<EOL>bgp.get()<EOL>neighbor = '<STR_LIT>'  <EOL><DEDENT>bgp_items = bgp.items()<EOL>if neighbor:<EOL><INDENT>neighbor_ip = napalm_base.helpers.ip(neighbor)<EOL><DEDENT>for bgp_group in bgp_items:<EOL><INDENT>bgp_group_name = bgp_group[<NUM_LIT:0>]<EOL>bgp_group_details = bgp_group[<NUM_LIT:1>]<EOL>bgp_config[bgp_group_name] = {<EOL>field: _DATATYPE_DEFAULT_.get(datatype)<EOL>for field, datatype in _GROUP_FIELDS_DATATYPE_MAP_.items()<EOL>if '<STR_LIT>' not in field<EOL>}<EOL>for elem in bgp_group_details:<EOL><INDENT>if not('<STR_LIT>' not in elem[<NUM_LIT:0>] and elem[<NUM_LIT:1>] is not None):<EOL><INDENT>continue<EOL><DEDENT>datatype = _GROUP_FIELDS_DATATYPE_MAP_.get(elem[<NUM_LIT:0>])<EOL>default = _DATATYPE_DEFAULT_.get(datatype)<EOL>key = elem[<NUM_LIT:0>]<EOL>value = elem[<NUM_LIT:1>]<EOL>if key in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if isinstance(value, list):<EOL><INDENT>value = '<STR_LIT:U+0020>'.join(value)<EOL><DEDENT><DEDENT>if key == '<STR_LIT>':<EOL><INDENT>value = napalm_base.helpers.convert(<EOL>napalm_base.helpers.ip, value, value)<EOL><DEDENT>if key == '<STR_LIT>':<EOL><INDENT>bgp_group_peers = value<EOL>continue<EOL><DEDENT>bgp_config[bgp_group_name].update({<EOL>key: napalm_base.helpers.convert(datatype, value, default)<EOL>})<EOL><DEDENT>prefix_limit_fields = {}<EOL>for elem in bgp_group_details:<EOL><INDENT>if '<STR_LIT>' in elem[<NUM_LIT:0>] and elem[<NUM_LIT:1>] is not None:<EOL><INDENT>datatype = _GROUP_FIELDS_DATATYPE_MAP_.get(elem[<NUM_LIT:0>])<EOL>default = _DATATYPE_DEFAULT_.get(datatype)<EOL>prefix_limit_fields.update({<EOL>elem[<NUM_LIT:0>].replace('<STR_LIT>', '<STR_LIT>'):<EOL>napalm_base.helpers.convert(datatype, elem[<NUM_LIT:1>], default)<EOL>})<EOL><DEDENT><DEDENT>bgp_config[bgp_group_name]['<STR_LIT>'] = build_prefix_limit(**prefix_limit_fields)<EOL>if '<STR_LIT>' in bgp_config[bgp_group_name].keys():<EOL><INDENT>del bgp_config[bgp_group_name]['<STR_LIT>']<EOL>if bgp_config[bgp_group_name]['<STR_LIT>'] == <NUM_LIT:0>:<EOL><INDENT>bgp_config[bgp_group_name]['<STR_LIT>'] = <NUM_LIT:64><EOL><DEDENT><DEDENT>bgp_config[bgp_group_name]['<STR_LIT>'] = {}<EOL>for bgp_group_neighbor in bgp_group_peers.items():<EOL><INDENT>bgp_peer_address = napalm_base.helpers.ip(bgp_group_neighbor[<NUM_LIT:0>])<EOL>if neighbor and bgp_peer_address != neighbor:<EOL><INDENT>continue  <EOL><DEDENT>bgp_group_details = bgp_group_neighbor[<NUM_LIT:1>]<EOL>bgp_peer_details = {<EOL>field: _DATATYPE_DEFAULT_.get(datatype)<EOL>for field, datatype in _PEER_FIELDS_DATATYPE_MAP_.items()<EOL>if '<STR_LIT>' not in field<EOL>}<EOL>for elem in bgp_group_details:<EOL><INDENT>if not('<STR_LIT>' not in elem[<NUM_LIT:0>] and elem[<NUM_LIT:1>] is not None):<EOL><INDENT>continue<EOL><DEDENT>datatype = _PEER_FIELDS_DATATYPE_MAP_.get(elem[<NUM_LIT:0>])<EOL>default = _DATATYPE_DEFAULT_.get(datatype)<EOL>key = elem[<NUM_LIT:0>]<EOL>value = elem[<NUM_LIT:1>]<EOL>if key in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if isinstance(value, list):<EOL><INDENT>value = '<STR_LIT:U+0020>'.join(value)<EOL><DEDENT><DEDENT>if key == '<STR_LIT>':<EOL><INDENT>value = napalm_base.helpers.convert(<EOL>napalm_base.helpers.ip, value, value)<EOL><DEDENT>bgp_peer_details.update({<EOL>key: napalm_base.helpers.convert(datatype, value, default)<EOL>})<EOL>bgp_peer_details['<STR_LIT>'] = napalm_base.helpers.as_number(<EOL>bgp_peer_details['<STR_LIT>'])<EOL>bgp_peer_details['<STR_LIT>'] = napalm_base.helpers.as_number(<EOL>bgp_peer_details['<STR_LIT>'])<EOL>if key == '<STR_LIT>':<EOL><INDENT>bgp_peer_details['<STR_LIT>'] = True<EOL>del bgp_peer_details['<STR_LIT>']<EOL><DEDENT><DEDENT>if '<STR_LIT>' in bgp_config[bgp_group_name].keys():<EOL><INDENT>bgp_peer_details['<STR_LIT>'] = True<EOL><DEDENT>prefix_limit_fields = {}<EOL>for elem in bgp_group_details:<EOL><INDENT>if '<STR_LIT>' in elem[<NUM_LIT:0>] and elem[<NUM_LIT:1>] is not None:<EOL><INDENT>datatype = _PEER_FIELDS_DATATYPE_MAP_.get(elem[<NUM_LIT:0>])<EOL>default = _DATATYPE_DEFAULT_.get(datatype)<EOL>prefix_limit_fields.update({<EOL>elem[<NUM_LIT:0>].replace('<STR_LIT>', '<STR_LIT>'):<EOL>napalm_base.helpers.convert(datatype, elem[<NUM_LIT:1>], default)<EOL>})<EOL><DEDENT><DEDENT>bgp_peer_details['<STR_LIT>'] = build_prefix_limit(**prefix_limit_fields)<EOL>bgp_config[bgp_group_name]['<STR_LIT>'][bgp_peer_address] = bgp_peer_details<EOL>if neighbor and bgp_peer_address == neighbor_ip:<EOL><INDENT>break  <EOL><DEDENT><DEDENT>if '<STR_LIT>' in bgp_config[bgp_group_name].keys():<EOL><INDENT>del bgp_config[bgp_group_name]['<STR_LIT>']<EOL><DEDENT><DEDENT>return bgp_config<EOL>
Return BGP configuration.