07-29-2017 10:07 AM
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
07-30-2017 01:54 AM
Have you tried using crud.delete(...)?
07-30-2017 02:05 AM
Yep I tried to crud.delete(provider,neighbor) but it raise the error :AttributeError: '_MetaInfoClass' object has no attribute 'namespaces'
07-30-2017 09:10 PM
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)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide