def get_bgp_config(self, group="<STR_LIT>", neighbor="<STR_LIT>"):
_GROUP_FIELD_MAP_ = {<EOL>"<STR_LIT:type>": "<STR_LIT:type>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:description>": "<STR_LIT:description>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>}<EOL>_PEER_FIELD_MAP_ = {<EOL>"<STR_LIT:description>": "<STR_LIT:description>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>}<EOL>_PROPERTY_FIELD_MAP_ = _GROUP_FIELD_MAP_.copy()<EOL>_PROPERTY_FIELD_MAP_.update(_PEER_FIELD_MAP_)<EOL>_PROPERTY_TYPE_MAP_ = {<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>": bool,<EOL>"<STR_LIT>": bool,<EOL>"<STR_LIT:description>": py23_compat.text_type,<EOL>"<STR_LIT>": bool,<EOL>"<STR_LIT:password>": py23_compat.text_type,<EOL>"<STR_LIT>": py23_compat.text_type,<EOL>"<STR_LIT>": list,<EOL>"<STR_LIT:type>": py23_compat.text_type,<EOL>"<STR_LIT>": py23_compat.text_type,<EOL>"<STR_LIT>": py23_compat.text_type,<EOL>"<STR_LIT>": bool,<EOL>}<EOL>_DATATYPE_DEFAULT_ = {py23_compat.text_type: "<STR_LIT>", int: <NUM_LIT:0>, bool: False, list: []}<EOL>def default_group_dict(local_as):<EOL><INDENT>group_dict = {}<EOL>group_dict.update(<EOL>{<EOL>key: _DATATYPE_DEFAULT_.get(_PROPERTY_TYPE_MAP_.get(prop))<EOL>for prop, key in _GROUP_FIELD_MAP_.items()<EOL>}<EOL>)<EOL>group_dict.update(<EOL>{"<STR_LIT>": {}, "<STR_LIT>": {}, "<STR_LIT>": local_as}<EOL>)  <EOL>return group_dict<EOL><DEDENT>def default_neighbor_dict(local_as):<EOL><INDENT>neighbor_dict = {}<EOL>neighbor_dict.update(<EOL>{<EOL>key: _DATATYPE_DEFAULT_.get(_PROPERTY_TYPE_MAP_.get(prop))<EOL>for prop, key in _PEER_FIELD_MAP_.items()<EOL>}<EOL>)  <EOL>neighbor_dict.update(<EOL>{"<STR_LIT>": {}, "<STR_LIT>": local_as, "<STR_LIT>": "<STR_LIT>"}<EOL>)  <EOL>return neighbor_dict<EOL><DEDENT>def parse_options(options, default_value=False):<EOL><INDENT>if not options:<EOL><INDENT>return {}<EOL><DEDENT>config_property = options[<NUM_LIT:0>]<EOL>field_name = _PROPERTY_FIELD_MAP_.get(config_property)<EOL>field_type = _PROPERTY_TYPE_MAP_.get(config_property)<EOL>field_value = _DATATYPE_DEFAULT_.get(field_type)  <EOL>if not field_type:<EOL><INDENT>return {}<EOL><DEDENT>if not default_value:<EOL><INDENT>if len(options) > <NUM_LIT:1>:<EOL><INDENT>field_value = napalm.base.helpers.convert(<EOL>field_type, options[<NUM_LIT:1>], _DATATYPE_DEFAULT_.get(field_type)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>if field_type is bool:<EOL><INDENT>field_value = True<EOL><DEDENT><DEDENT><DEDENT>if field_name is not None:<EOL><INDENT>return {field_name: field_value}<EOL><DEDENT>elif config_property in ["<STR_LIT>", "<STR_LIT:password>"]:<EOL><INDENT>if config_property == "<STR_LIT:password>":<EOL><INDENT>return {"<STR_LIT>": py23_compat.text_type(options[<NUM_LIT:2>])}<EOL><DEDENT>if config_property == "<STR_LIT>":<EOL><INDENT>direction = None<EOL>if len(options) == <NUM_LIT:3>:<EOL><INDENT>direction = options[<NUM_LIT:2>]<EOL>field_value = field_type(options[<NUM_LIT:1>])  <EOL><DEDENT>elif len(options) == <NUM_LIT:2>:<EOL><INDENT>direction = options[<NUM_LIT:1>]<EOL><DEDENT>if direction == "<STR_LIT>":<EOL><INDENT>field_name = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>field_name = "<STR_LIT>"<EOL><DEDENT>return {field_name: field_value}<EOL><DEDENT><DEDENT>return {}<EOL><DEDENT>bgp_config = {}<EOL>commands = ["<STR_LIT>"]<EOL>bgp_conf = self.device.run_commands(commands, encoding="<STR_LIT:text>")[<NUM_LIT:0>].get(<EOL>"<STR_LIT>", "<STR_LIT>"<EOL>)<EOL>bgp_conf_lines = bgp_conf.splitlines()<EOL>bgp_neighbors = {}<EOL>if not group:<EOL><INDENT>neighbor = "<STR_LIT>"  <EOL><DEDENT>local_as = <NUM_LIT:0><EOL>bgp_neighbors = {}<EOL>for bgp_conf_line in bgp_conf_lines:<EOL><INDENT>default_value = False<EOL>bgp_conf_line = bgp_conf_line.strip()<EOL>if bgp_conf_line.startswith("<STR_LIT>"):<EOL><INDENT>local_as = int(bgp_conf_line.replace("<STR_LIT>", "<STR_LIT>").strip())<EOL>continue<EOL><DEDENT>if not (<EOL>bgp_conf_line.startswith("<STR_LIT>")<EOL>or bgp_conf_line.startswith("<STR_LIT>")<EOL>):<EOL><INDENT>continue<EOL><DEDENT>if bgp_conf_line.startswith("<STR_LIT>"):<EOL><INDENT>default_value = True<EOL><DEDENT>bgp_conf_line = bgp_conf_line.replace("<STR_LIT>", "<STR_LIT>").replace(<EOL>"<STR_LIT>", "<STR_LIT>"<EOL>)<EOL>bgp_conf_line_details = bgp_conf_line.split()<EOL>group_or_neighbor = py23_compat.text_type(bgp_conf_line_details[<NUM_LIT:0>])<EOL>options = bgp_conf_line_details[<NUM_LIT:1>:]<EOL>try:<EOL><INDENT>IPAddress(group_or_neighbor)<EOL>peer_address = group_or_neighbor<EOL>if peer_address not in bgp_neighbors:<EOL><INDENT>bgp_neighbors[peer_address] = default_neighbor_dict(local_as)<EOL><DEDENT>if options[<NUM_LIT:0>] == "<STR_LIT>":<EOL><INDENT>bgp_neighbors[peer_address]["<STR_LIT>"] = options[<NUM_LIT:1>]<EOL><DEDENT>bgp_neighbors[peer_address].update(<EOL>parse_options(options, default_value)<EOL>)<EOL><DEDENT>except AddrFormatError:<EOL><INDENT>group_name = group_or_neighbor<EOL>if group and group_name != group:<EOL><INDENT>continue<EOL><DEDENT>if group_name not in bgp_config.keys():<EOL><INDENT>bgp_config[group_name] = default_group_dict(local_as)<EOL><DEDENT>bgp_config[group_name].update(parse_options(options, default_value))<EOL><DEDENT><DEDENT>for peer, peer_details in bgp_neighbors.items():<EOL><INDENT>peer_group = peer_details.pop("<STR_LIT>", None)<EOL>if not peer_group:<EOL><INDENT>peer_group = "<STR_LIT:_>"<EOL><DEDENT>if peer_group not in bgp_config:<EOL><INDENT>bgp_config[peer_group] = default_group_dict(local_as)<EOL><DEDENT>bgp_config[peer_group]["<STR_LIT>"][peer] = peer_details<EOL><DEDENT>return bgp_config<EOL>
Implementation of NAPALM method get_bgp_config.