Пример #1
0
def neighbours(session, proto="cdp"):
    """
    Get the node list and collect the LLDP instance list
    :param session: APIC session object
    :param proto: string, contains discovery protocol name
    :return: list of dict: containing lldp details
    """

    nodes = Node.get_deep(session, include_concrete=True)
    lldps = []
    LOG.info("Discovery protocol used: %s", proto)
    for node in nodes:
        if proto == "cdp":
            node_concrete = node.get_children(child_type=ConcreteCdp)
        elif proto == "lldp":
            node_concrete = node.get_children(child_type=ConcreteLLdp)
        else:
            LOG.info("No discovery data found!")
            return ["No discovery data found!"]

        for node_concrete_lldp_obj in node_concrete:
            lldps.append(node_concrete_lldp_obj)

    neig = parse_discovery(lldps, proto)
    LOG.debug("Neighbour Data: %s", str(neig))
    return neig
Пример #2
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"])
Пример #3
0
    def get_nodes_object(self, node=None):
        self.logging.info("get nodes")

        if not node:
            nodes = Node.get_deep(self.session, include_concrete=True)
        else:
            nodes = Node.get(self.session, None, node)

        self.logging.info("Got it")

        return nodes
Пример #4
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"
                 ])
    })
Пример #5
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)