当前位置: 首页>>代码示例>>Python>>正文


Python MoDirectory.lookupByClass方法代码示例

本文整理汇总了Python中cobra.mit.access.MoDirectory.lookupByClass方法的典型用法代码示例。如果您正苦于以下问题:Python MoDirectory.lookupByClass方法的具体用法?Python MoDirectory.lookupByClass怎么用?Python MoDirectory.lookupByClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cobra.mit.access.MoDirectory的用法示例。


在下文中一共展示了MoDirectory.lookupByClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import lookupByClass [as 别名]
def main(host, username, password, node, interface):
    apic = "https://%s" % host
    print("Connecting to APIC : %s" % apic)
    moDir = MoDirectory(LoginSession(apic, username, password))
    moDir.login()

    nodeblk_dict = defaultdict(list)
    nodeblk_list = moDir.lookupByClass("infraNodeBlk")
    node_found = False
    for nodeblkMO in nodeblk_list:
        if int(nodeblkMO.from_) > int(node) or int(nodeblkMO.to_) < int(node):
            continue
        else:
            node_found = True
            node_dn = '/'.join(str(nodeblkMO.dn).split('/')[:3])
            nodeblk_dict[node_dn].append(str(nodeblkMO.dn))
    if node_found is False:
        print("Switch Node {", node, "} DOES NOT exist!")
        exit(1)
    if debug is True:
        print("Printing nodeblk_dict.......")
        for key, value in nodeblk_dict.items():
            print(key, ":", value)
        print("-----------------------------")

    port_dict = {}
    RsAccPortP_list = moDir.lookupByClass("infraRsAccPortP")
    for RsAccPortPMO in RsAccPortP_list:
        portk = str(str(RsAccPortPMO.dn).split('[')[1])[:-1]
        port_dict[portk] = '/'.join(str(RsAccPortPMO.dn).split('/')[:3])

    if debug is True:
        print("Printing port_dict.......")
        for key, value in port_dict.items():
            print(key, ":", value)

        print("-----------------------------")

    Portblk_list = moDir.lookupByClass("infraPortBlk")
    interface_found = False
    for temp_port in Portblk_list:
        if int(interface) == int(temp_port.fromPort):
            interface_found = True
            intP = '/'.join(str(temp_port.dn).split('/')[:3])
            if port_dict[intP] in nodeblk_dict:
                m = re.match("accportprof-(?P<first>.+)", str(temp_port.dn).split('/')[2])
                print("Interface Profile Name => ", m.group("first"))
                print("Interface Profile DN =>", intP)
                n = re.match("nprof-(?P<first>.+)", str(port_dict[intP]).split('/')[2])
                print("Switch Node Profile Name =>", n.group("first"))
                print("Switch Node Profile DN =>", port_dict[intP])
    if interface_found is False:
        print("Interface {", interface, "} DOES NOT exist!")
        exit(1)
开发者ID:gent79reid,项目名称:ACI,代码行数:56,代码来源:find_node_port_profile.py

示例2: main

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import lookupByClass [as 别名]
def main(host, username, password, tenant):
    apic = "https://%s" % host
    print("Connecting to APIC : %s" % apic)
    moDir = MoDirectory(LoginSession(apic, username, password))
    moDir.login()

    t_obj_list = moDir.lookupByClass("fvTenant")
    for t_mo in t_obj_list:
        print("Tenant name =>",t_mo.dn)
        if t_mo.name == tenant:
            bd_list = moDir.lookupByClass("fvBD", t_mo.dn)
            for mo in bd_list:
                print("NAME: {:10s}".format(mo.name))
                print("DN: {:10s}".format(mo.dn))
                print("MAC: {:10s}".format(mo.mac))
                print("UID: {:10s}".format(mo.uid))
                print("arpFlood: {:10s}".format(mo.arpFlood))
                print("MUT: {:10s}".format(mo.mtu))
                print()
            return
开发者ID:gent79reid,项目名称:ACI,代码行数:22,代码来源:list_bd_in_tenant.py

示例3: get_tenant

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import lookupByClass [as 别名]
def get_tenant():
    with open("/home/app/data/logs.txt", "a") as log_file:
        log_file.write("==================================================" + "\n")
        log_file.write("Received API Request from Client. Sending Response" + "\n")
        log_file.write("==================================================" + "\n")

    apicUrl = 'https://172.17.0.1/'
    loginSession = createCertSession()
    #loginSession = LoginSession(apicUrl, 'admin', 'ins3965!')
    #loginSession = cobra.mit.session.LoginSession('https://10.22.47.171', 'admin', 'ins3965!')
    moDir = MoDirectory(loginSession)
    moDir.login()
    tenantMo = moDir.lookupByClass('fvTenant');
    moDir.logout()
    #print json.dumps(tenantMo)
    return respFormatJsonMos(tenantMo, tenantMo.totalCount)
开发者ID:clakits,项目名称:ACI-CL,代码行数:18,代码来源:plugin_server.py

示例4: LoginSession

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import lookupByClass [as 别名]
import logging, json

from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession


# uncomment the below to get more verbose output
# for debugging
"""
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
"""

session = LoginSession('https://apic:8888', 'admin', '[email protected]@y')
moDir = MoDirectory(session)
moDir.login()
tenant1Mo = moDir.lookupByClass("dhcpClient")

for c in tenant1Mo:
	print(c.dn, c.model, c.name, c.ip)

moDir.logout()


开发者ID:rschmied,项目名称:apic-workshop,代码行数:29,代码来源:cobra-sdk.py

示例5: LoginSession

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import lookupByClass [as 别名]
# Set just the URLLIB3 logging level to INFO
requests_log.setLevel(logging.INFO)
requests_log.propagate = True

requests.packages.urllib3.disable_warnings()

aci_class = sys.argv[1]
session = LoginSession('https://172.21.208.173', 'admin','C1sc0123')
moDir = MoDirectory(session)
moDir.login()

from cobra.mit.request import ConfigRequest

#import the tenant class from the model
from cobra.model.fv import Tenant
# Get the top level policy universe directory
uniMo = moDir.lookupByDn('uni')

## create the tenant object
#fvTenantMo = Tenant(uniMo, 'test1111111111')
#fvTenantMo.delete()#

#configReq = ConfigRequest()
#configReq.addMo(fvTenantMo)
#moDir.commit(configReq)

obj_list = moDir.lookupByClass(aci_class)
#
for mo in obj_list:
	print "{} -> {}".format(mo.name,mo.dn)
开发者ID:gent79reid,项目名称:ACI,代码行数:32,代码来源:list_tenant.py


注:本文中的cobra.mit.access.MoDirectory.lookupByClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。