Пример #1
0
def main():
    """
    Main show Cdps routine
    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = 'Simple application that logs on to the APIC and displays all the CDP neighbours.'
    creds = ACI.Credentials('apic', description)
    args = creds.get()

    # Login to APIC
    session = ACI.Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        sys.exit(0)

    nodes = Node.get_deep(session, include_concrete=True)
    cdps = []
    for node in nodes:
        node_concreteCdp = node.get_children(child_type=ConcreteCdp)
        for node_concreteCdp_obj in node_concreteCdp:
            cdps.append(node_concreteCdp_obj)

    tables = ConcreteCdp.get_table(cdps)
    output_list = []
    for table in tables:
        for table_data in table.data:
            if table_data not in output_list:
                output_list.append(table_data)
    print tabulate(output_list, headers=["Node-ID", "Local Interface", "Neighbour Device", "Neighbour Platform", "Neighbour Interface"])
Пример #2
0
 def test_get_table(self):
     """
     Test ConcreteCdp create table function
     """
     node_id1 = '103'
     node1 = Node(node_id1)
     concreteCdp1 = ConcreteCdp(node1)
     concreteCdpIf1 = ConcreteCdpIf(concreteCdp1)
     concreteCdp1.add_child(concreteCdpIf1)
     node_id2 = '103'
     node2 = Node(node_id2)
     concreteCdp2 = ConcreteCdp(node2)
     concreteCdpIf2 = ConcreteCdpIf(concreteCdp2)
     concreteCdp2.add_child(concreteCdpIf2)
     concreteCdps = [concreteCdp1, concreteCdp2]
     self.assertTrue(
         isinstance(
             ConcreteCdp.get_table(concreteCdps)[0],
             Table))
Пример #3
0
def main():
    """
    Main show Cdps routine
    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = ('Simple application that logs on to the APIC'
                   'and displays all the CDP neighbours.')
    creds = ACI.Credentials('apic', description)
    args = creds.get()

    # Login to APIC
    session = ACI.Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        return

    nodes = Node.get_deep(session, include_concrete=True)
    cdps = []
    for node in nodes:
        node_concrete_cdp = node.get_children(child_type=ConcreteCdp)
        for node_concrete_cdp_obj in node_concrete_cdp:
            cdps.append(node_concrete_cdp_obj)

    tables = ConcreteCdp.get_table(cdps)
    output_list = []
    for table in tables:
        for table_data in table.data:
            if table_data not in output_list:
                output_list.append(table_data)
    print({
        tabulate(output_list,
                 headers=[
                     "Node-ID", "Local Interface", "Neighbour Device",
                     "Neighbour Platform", "Neighbour Interface"
                 ])
    })
Пример #4
0
def main():
    """
    Main show Cdps routine
    :return: None
    """
    # Take login credentials from the command line if provided
    start_time = time.time()

    description = ('Simple application that logs on to the APIC'
                   'and displays all the CDP/LLDP neighbours.')
    creds = ACI.Credentials('apic', description)
    creds.add_argument('--protocol', choices=["cdp", "lldp", "both"], default="both", help='Choose if you want to see CDP/LLDP or both. Default is both')
    args = creds.get()

    # Login to APIC
    session = ACI.Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        return
    else:
        print('%% Login to APIC: Successful')

    # Start time count at this point, otherwise takes into consideration the amount of time taken to input the password
    start_time = time.time()

    print ("Proceeding to next step...")
    print ("Retrieving node information...")
    nodes = Node.get_deep(session, include_concrete=True)
    cdp_count = 0
    lldp_count = 0

    if args.protocol == "both" or args.protocol == "cdp":
        print "Processing CDP Information..."
        cdps = []
        for node in nodes:
            node_concrete_cdp = node.get_children(child_type=ConcreteCdp)
            for node_concrete_cdp_obj in node_concrete_cdp:
                cdps.append(node_concrete_cdp_obj)

        tables = ConcreteCdp.get_table(cdps)
        cdp_list = []
        for table in tables:
            for table_data in table.data:
                #print table_data
                if table_data not in cdp_list:
                    cdp_list.append(table_data)
                    cdp_count += 1

        print ("=" * 100)
        print ("CDP: Total Entries [" + str(cdp_count) + "]")
        print ("=" * 100)
        print tabulate(cdp_list, headers=["Node-ID",
                                          "Local Interface",
                                          "Neighbour Device",
                                          "Neighbour Platform",
                                          "Neighbour Interface"])

    if args.protocol == "both" or args.protocol == "lldp":
        print "Processing LLDP Information..."
        lldps = []
        for node in nodes:
            node_concrete_lldp = node.get_children(child_type=ConcreteLLdp)
            for node_concrete_lldp_obj in node_concrete_lldp:
                lldps.append(node_concrete_lldp_obj)

        tables = ConcreteLLdp.get_table(lldps)
        lldp_list = []
        for table in tables:
            for table_data in table.data:
                #print table_data
                if table_data not in lldp_list:
                    lldp_list.append(table_data)
                    lldp_count += 1

        print ("=" * 100)
        print ("LLDP: Total Entries [" + str(lldp_count) + "]")
        print ("=" * 100)
        print(tabulate(lldp_list, headers=["Node-ID",
                                           "Ip",
                                           "Name",
                                           "Chassis_id_t",
                                           "Neighbour Platform",
                                           "Neighbour Interface"]))

    print ("#" * 80)
    finish_time = time.time()
    print ("Started @ {}".format(time.asctime(time.localtime(start_time))))
    print ("Ended @ {}".format(time.asctime(time.localtime(finish_time))))
    print("--- Total Execution Time: %s seconds ---" % (finish_time - start_time))
    print ("#" * 80)