cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1271
Views
7
Helpful
3
Replies

How to remove a specific bgp neighbor

Treemanzhou1
Level 1
Level 1

Hi developers

     Here is my script to create a bgp neighbor , How can I  remove the neighbor then?  I tried to

def config_bgp(bgp):

    """Add config data to bgp object."""

    # global configuration

    instance = bgp.Instance()

    instance.instance_name = "default"

    instance_as = instance.InstanceAs()

    instance_as.as_ = 0

    four_byte_as = instance_as.FourByteAs()

    four_byte_as.as_ = 65000

    four_byte_as.bgp_running = Empty()

    # global address family

    global_af = four_byte_as.default_vrf.global_.global_afs.GlobalAf()

    global_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamilyEnum.ipv4_unicast

    global_af.enable = Empty()

    four_byte_as.default_vrf.global_.global_afs.global_af.append(global_af)

    instance_as.four_byte_as.append(four_byte_as)

    instance.instance_as.append(instance_as)

    bgp.instance.append(instance)

    # configure IBGP neighbor group

    neighbor_groups = four_byte_as.default_vrf.bgp_entity.neighbor_groups

    neighbor_group = neighbor_groups.NeighborGroup()

    neighbor_group.neighbor_group_name = "IBGP"

    neighbor_group.create = Empty()

    # remote AS

    neighbor_group.remote_as.as_xx = 0

    neighbor_group.remote_as.as_yy = 65001

    neighbor_group.update_source_interface = "Loopback0"

    neighbor_groups.neighbor_group.append(neighbor_group)

    # ipv4 unicast

    neighbor_group_af = neighbor_group.neighbor_group_afs.NeighborGroupAf()

    neighbor_group_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamilyEnum.ipv4_unicast

    neighbor_group_af.activate = Empty()

    neighbor_group_afs = neighbor_group.neighbor_group_afs

    neighbor_group_afs.neighbor_group_af.append(neighbor_group_af)

    # configure IBGP neighbor

    neighbor = four_byte_as.default_vrf.bgp_entity.neighbors.Neighbor()

    neighbor.neighbor_address = "172.16.1.3"

    neighbor.neighbor_group_add_member = "IBGP"

    four_byte_as.default_vrf.bgp_entity.neighbors.neighbor.append(neighbor)

 

if __name__ == "__main__":

    # create NETCONF provider

    provider = NetconfServiceProvider(address="10.2.2.2.",

                                      port=830,

                                      username="cisco",

                                      password="123456",

                                      protocol="ssh")

    # create CRUD service

    crud = CRUDService()

    bgp = xr_ipv4_bgp_cfg.Bgp()  # create object

    config_bgp(bgp)  # add object configuration

    # create configuration on NETCONF device

    crud.create(provider,neighbor)

    provider.close()

    exit()

# End of script

3 Replies 3

einarnn
Cisco Employee
Cisco Employee

Have you tried using crud.delete(...)?

Yep I tried to crud.delete(provider,neighbor) but it raise the error :AttributeError: '_MetaInfoClass' object has no attribute 'namespaces'

abhirame
Cisco Employee
Cisco Employee

Can you try the below?

bgp = xr_ipv4_bgp_cfg.Bgp()  # create object

instance = bgp.Instance()

instance.instance_name = "default"

instance_as = instance.InstanceAs()

instance_as.as_ = 0

four_byte_as = instance_as.FourByteAs()

four_byte_as.as_ = 65000

global_af = four_byte_as.default_vrf.global_.global_afs.GlobalAf()

global_af.af_name = xr_ipv4_bgp_datatypes.BgpAddressFamilyEnum.ipv4_unicast

four_byte_as.default_vrf.global_.global_afs.global_af.append(global_af)

neighbor = four_byte_as.default_vrf.bgp_entity.neighbors.Neighbor()

neighbor.neighbor_address = "172.16.1.3"

four_byte_as.default_vrf.bgp_entity.neighbors.neighbor.append(neighbor)

instance_as.four_byte_as.append(four_byte_as)

instance.instance_as.append(instance_as)

bgp.instance.append(instance)

crud.delete(provider, neighbor)

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: