Пример #1
0
def get_mo_for_interface(nodeid, portid):
    cq = ClassQuery('fabricPathEpCont')
    cq.propFilter = 'eq(fabricPathEpCont.nodeId, "{0}")'.format(nodeid)
    cq.subtree = 'children'
    cq.subtreeClassFilter = 'fabricPathEp'
    req = moDir.query(cq)
    for key in req[0].children:
        # children method applied to the query result will return a list of child objects
        # req[0] is fabricPathEpCont (leaf), children are fabricPathEp (ports)
        if key.name == portid:
            return format(key.dn)
Пример #2
0
    if len(sys.argv) != 5:
        print 'Usage: apic_show-mac-address.py <hostname> <username> <password> <mac-address>'
        sys.exit()
    else:
        hostname, username, password, macaddress = sys.argv[1:]
        url = 'https://' + hostname
        print "Logging on APIC..."

        try:
            #
            lls = LoginSession(url, username, password, secure=False)
            md = MoDirectory(lls)
            md.login()
            q = ClassQuery('fvCEp')
            q.subtree = 'children'
            q.subtreeClassFilter = 'fvRsCEpToPathEp'
            mos = md.query(q)

            #Other variables
            hasmacaddress = False
            epglists = {}
            i = -1

            ## Verifying all mac address:
            for mo in mos:
                for child in mo.rscEpToPathEp:
                    line = str(child.dn)
                    i = i + 1
                    if (macaddress in line):
                        hasmacaddress = True
                        epglists[i] = line
    if len(sys.argv) != 5:
        print 'Usage: apic_show-mac-address.py <hostname> <username> <password> <mac-address>'
        sys.exit()
    else:
        hostname, username, password, macaddress = sys.argv[1:]
        url = 'https://' + hostname
        print "Logging on APIC..."

        try:
            #
            lls = LoginSession(url, username, password, secure=False)
            md = MoDirectory(lls)
            md.login()
            q = ClassQuery('fvCEp')
            q.subtree = 'children'
            q.subtreeClassFilter = 'fvRsCEpToPathEp'
            mos = md.query(q)

            #Other variables
            hasmacaddress = False
            epglists = {}
            i = -1
        
            ## Verifying all mac address:
            for mo in mos:
                for child in mo.rscEpToPathEp:
                       line = str(child.dn)
                       i = i + 1
                       if (macaddress in line):
                           hasmacaddress = True
                           epglists[i] = line