ciscoconfparse BGP нет описания на одном из соседей - PullRequest
0 голосов
/ 20 июня 2020

Я пытаюсь использовать ciscoconfparse для извлечения соседа, удаленного as и описания в словарь. однако у одного из соседей нет описания. следовательно, он не вернет значение

может ли кто-нибудь помочь, что было бы правильным способом получить все соседние значения


Config:
router bgp 42098001
 neighbor SERVER peer-group
 neighbor SERVER remote-as 64700
 neighbor 10.29.0.65 remote-as 1111
 neighbor 10.29.0.65 description to ZZZ
 neighbor 10.29.0.73 remote-as 2222
 neighbor 10.29.0.73 description to AAA
 neighbor 10.29.0.81 remote-as 3333
 neighbor 10.29.0.81 description to BBB
 neighbor 10.29.0.90 remote-as 4209800190
 neighbor 10.29.0.90 description to ABC 
 neighbor 10.232.122.170 remote-as 64700
 neighbor 10.232.122.170 description ABD
 neighbor 10.237.34.2 remote-as 4209800192
 neighbor 10.237.34.2 description to CCC
    bgp_as_name = confparse.find_all_children(r"^router bgp")

    for details in bgp_as_name:
        if 'remote-as' in details:
            remote_ip = details.strip().rsplit(' ')[1]
            as_number = details.strip().rsplit(' ')[3]
            #print(remote_ip)

        if 'description' in details:
            description = details.strip().rsplit(' ')[3:]
            desc = (' ').join(description)
            bgp_as_ip.update({'description': desc})
            print(bgp_as_ip)


    #BGP route-map
    bgp_route_map = confparse.find_all_children(r"^router bgp")
    for routemap in bgp_route_map:
        if 'route-map' in routemap:
            bgp_routemap_slice1 = routemap.strip().split(' ')[0:2]
            bgp_routemap_slice2 = routemap.strip().split(' ')[-2:]
            bgp_routemap_combine = bgp_routemap_slice1 + bgp_routemap_slice2
            bgp_route_map = bgp_routemap_combine[1:4]
            print(bgp_route_map)
            #bgp_as_ip.update({'route-map': bgp_route_map})
            #print(bgp_as_ip)
RESULT
{'remote_ip': '10.29.0.65', 'as_num': '1111', 'description': 'to ZZZ'}
{'remote_ip': '10.29.0.73', 'as_num': '2222', 'description': 'to AAA'}
{'remote_ip': '10.29.0.81', 'as_num': '3333', 'description': 'to BBB'}
{'remote_ip': '10.29.0.90', 'as_num': '4201', 'description': 'to ABC'}
{'remote_ip': '10.232.122.170', 'as_num': '64700', 'description': 'ABD'}
{'remote_ip': '10.237.34.2', 'as_num': '4209', 'description': 'to CCC'}

> Отсутствующие информация соседний СЕРВЕР

...