def cdp_neighbors_json(device_name):
    response = odl_http_get(
        url_neighbors, {"node-id": device_name}, "application/json", expected_status_code=(200, 404)
    )
    j = json.loads(response.text)
    container = j["cdp"]["nodes"]["node"][0]
    mgmt_name = management_interface(device_name)
    neighbor_set = set()
    if "neighbors" in container:
        neighbors = container["neighbors"]
        #       print(json.dumps(neighbors, indent=2))
        if "summaries" in neighbors:
            summary = neighbors["summaries"]["summary"]
            for device_info in summary:
                neighbor_id = device_info["device-id"]
                neighbor_interface = device_info["cdp-neighbor"][0]["port-id"]
                device_interface = device_info["interface-name"]
                if device_interface in mgmt_name:
                    continue
                neighbor_info = (
                    device_name,
                    device_interface.encode("utf8"),
                    neighbor_id.encode("utf8"),
                    neighbor_interface.encode("utf8"),
                )
                neighbor_set.add(neighbor_info)
            return neighbor_set
Beispiel #2
0
def link_info():
    #def main():
    ii = 0
    link_info_dic = {}
    for device_name in inventory_connected():

        response = odl_http_get(url_neighbors, {'node-id': device_name},
                                'application/json',
                                expected_status_code=(200, 404))
        l = json.loads(response.text)
        container_l = l["cdp"]["nodes"]["node"][0]
        mgmt_name = management_interface(device_name)

        if "neighbors" in container_l:
            neighbors = container_l["neighbors"]
            #           print(json.dumps(neighbors, indent=2))
            if "summaries" in neighbors:
                summary = neighbors["summaries"]["summary"]
                for device_info in summary:
                    neighbor_id = device_info["device-id"]
                    if neighbor_id == "kcy":
                        neighbor_id = 'iosxrv-1'
                    elif neighbor_id == "lax":
                        neighbor_id = 'iosxrv-2'
                    elif neighbor_id == "min":
                        neighbor_id = 'iosxrv-3'
                    elif neighbor_id == "por":
                        neighbor_id = 'iosxrv-4'
                    elif neighbor_id == "san":
                        neighbor_id = 'iosxrv-5'
                    elif neighbor_id == "sea":
                        neighbor_id = 'iosxrv-6'
                    elif neighbor_id == "sfc":
                        neighbor_id = 'iosxrv-7'
                    else:
                        neighbor_id = 'iosxrv-8'
                    device_interface = device_info["interface-name"]
                    if device_interface in mgmt_name:
                        continue
                    link_info = (device_name, neighbor_id.encode('utf8'))
                    link_info_re = (neighbor_id.encode('utf8'), device_name)
                    jj = 0
                    flag = 1
                    while ii > jj:
                        if link_info_dic[jj] == link_info or link_info_dic[
                                jj] == link_info_re:
                            flag = 0
                            jj = jj + 1
                        else:
                            jj = jj + 1
                    if flag == 1:
                        link_info_dic[ii] = link_info
                        ii = ii + 1
                    else:
                        jj = 0


#                   return link_info_set
    return link_info_dic
def link_info():
    # def main():
    ii = 0
    link_info_dic = {}
    for device_name in inventory_connected():

        response = odl_http_get(
            url_neighbors, {"node-id": device_name}, "application/json", expected_status_code=(200, 404)
        )
        l = json.loads(response.text)
        container_l = l["cdp"]["nodes"]["node"][0]
        mgmt_name = management_interface(device_name)

        if "neighbors" in container_l:
            neighbors = container_l["neighbors"]
            #           print(json.dumps(neighbors, indent=2))
            if "summaries" in neighbors:
                summary = neighbors["summaries"]["summary"]
                for device_info in summary:
                    neighbor_id = device_info["device-id"]
                    if neighbor_id == "kcy":
                        neighbor_id = "iosxrv-1"
                    elif neighbor_id == "lax":
                        neighbor_id = "iosxrv-2"
                    elif neighbor_id == "min":
                        neighbor_id = "iosxrv-3"
                    elif neighbor_id == "por":
                        neighbor_id = "iosxrv-4"
                    elif neighbor_id == "san":
                        neighbor_id = "iosxrv-5"
                    elif neighbor_id == "sea":
                        neighbor_id = "iosxrv-6"
                    elif neighbor_id == "sfc":
                        neighbor_id = "iosxrv-7"
                    else:
                        neighbor_id = "iosxrv-8"
                    device_interface = device_info["interface-name"]
                    if device_interface in mgmt_name:
                        continue
                    link_info = (device_name, neighbor_id.encode("utf8"))
                    link_info_re = (neighbor_id.encode("utf8"), device_name)
                    jj = 0
                    flag = 1
                    while ii > jj:
                        if link_info_dic[jj] == link_info or link_info_dic[jj] == link_info_re:
                            flag = 0
                            jj = jj + 1
                        else:
                            jj = jj + 1
                    if flag == 1:
                        link_info_dic[ii] = link_info
                        ii = ii + 1
                    else:
                        jj = 0

    #                   return link_info_set
    return link_info_dic
Beispiel #4
0
def cdp_neighbors_json(device_name):
    response = odl_http_get(url_neighbors, {'node-id': device_name},
                            'application/json',
                            expected_status_code=(200, 404))
    j = json.loads(response.text)
    container = j["cdp"]["nodes"]["node"][0]
    mgmt_name = management_interface(device_name)
    neighbor_set = set()
    if "neighbors" in container:
        neighbors = container["neighbors"]
        #       print(json.dumps(neighbors, indent=2))
        if "summaries" in neighbors:
            summary = neighbors["summaries"]["summary"]
            for device_info in summary:
                neighbor_id = device_info["device-id"]
                neighbor_interface = device_info["cdp-neighbor"][0]["port-id"]
                device_interface = device_info["interface-name"]
                if device_interface in mgmt_name:
                    continue
                neighbor_info = (device_name, device_interface.encode('utf8'),
                                 neighbor_id.encode('utf8'),
                                 neighbor_interface.encode('utf8'))
                neighbor_set.add(neighbor_info)
            return neighbor_set