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


Python MoDirectory.logout方法代码示例

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


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

示例1: APICHandler

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import logout [as 别名]
class APICHandler():
    def __init__(self):
        self.host = 'https://192.168.1.100'
        self.user = 'admin'
        self.pwd = 'GDTlabs123'
        self.session = None

    def do_login(self):
        loginSession = LoginSession(self.host, self.user, self.pwd)
        self.session = MoDirectory(loginSession)
        self.session.login()
        # print loginSession.cookie
        return self.session

    def target_location_lookup(self, active_session, location):
        change_location = self.session.lookupByDn(location)
        return change_location

    def update_config(self, active_session, change_location):
        configReq = ConfigRequest()
        configReq.addMo(change_location)
        self.session.commit(configReq)

    def logout(self, active_session):
        self.session.logout()
开发者ID:GDT-Labs,项目名称:APICTools,代码行数:27,代码来源:APICCoreFuncs.py

示例2: get_tenant

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import logout [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

示例3: LoginSession

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import logout [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

示例4: __init__

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import logout [as 别名]
class apic_base:
    def __init__(self):
        self.session = None
        self.moDir = None
        self.configReq = None
        self.uniMo = None

    """ Authentication """
    def login(self, url, user, password):
        """
        Login to the APIC
        :param url:
        :param user:
        :param password:
        :return:
        """
        self.session = LoginSession(url, user, password)
        self.moDir = MoDirectory(self.session)
        self.moDir.login()
        self.configReq = ConfigRequest()
        self.uniMo = self.moDir.lookupByDn('uni')

    def logout(self):
        """
        Logout from the APIC
        :return:
        """
        self.moDir.logout()

    """ Commits """
    def commit(self, commit_object):
        """
        Commits object changes to controller
        :param commit_object:
        :return:
        """

        self.configReq = ConfigRequest()
        self.configReq.addMo(commit_object)
        self.moDir.commit(self.configReq)

    """ Queries """
    def query_child_objects(self, dn_query_name):
        """
        Retrieve the object using the dn and return all the children under it
        :param dn_query_name: dn of the management object
        :return:
        """
        dn_query = DnQuery(dn_query_name)
        dn_query.queryTarget = QUERY_TARGET_CHILDREN
        child_mos = self.moDir.query(dn_query)
        return child_mos

    """ Generic Deletes """
    def delete_dn_by_pattern(self, dn_object_list, dn_pattern, recursive):
        """
        Travers a dn list and compare each member with a pattern. If there is a match that object will be removed.
        If recursive is true, the algorithm will also do a recursive look for the children of each object looking
        for the pattern: will stop only when there is no more children to look for.
        :param dn_object_list:
        :param dn_pattern:
        :param recursive:
        :return:
        """
        for dn_object in dn_object_list:
            if dn_pattern in str(dn_object.dn):
                try:
                    self.delete_by_dn(str(dn_object.dn))
                except CommitError as e:
                    print 'Could not delete ' + str(dn_object.dn) + ' -> ' + str(e)
            elif recursive:
                children = self.query_child_objects(dn_object.dn)
                if children is not None:
                    self.delete_dn_by_pattern(children, dn_pattern, recursive)

    def delete_by_dn(self, dn_name):
        """
        Retrieve a mo and it removes it from the APIC
        :param dn_name:
        :return:
        """
        dn_object = self.moDir.lookupByDn(dn_name)
        if dn_object is not None:
            dn_object.delete()
            self.commit(dn_object)

    """ Tenants """
    def create_tenant(self, tenant_name):
        """
        Creates a tenant and commit changes to controller
        :param tenant_name:
        :return:
        """
        fv_tenant_mo = Tenant(self.uniMo, tenant_name)
        self.commit(fv_tenant_mo)
        return fv_tenant_mo

    def delete_tenant(self, tenant_dn):
        """
        Deletes a tenant and commit changes to controller
#.........这里部分代码省略.........
开发者ID:chapeter,项目名称:NCAplus,代码行数:103,代码来源:apic_base.py

示例5: home

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import logout [as 别名]
def home():
    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")

    reply = None
    try:
        apicUrl = 'https://172.17.0.1/'
        loginSession = createCertSession()
    

        #loginSession = cobra.mit.session.LoginSession('https://10.22.47.171', 'admin', 'ins3965!')
        moDir = MoDirectory(loginSession)
        moDir.login()

        tableList = []
        #row =  ('TN', 'AP/L2OUT', 'EPG/InstP', 'CEP', 'IP', 'Type', 'PATH', 'PORT', 'POD', 'ENCAP', 'BD:CTX')
        #tableList.append(row)
        try:
            row ={}
            q = ClassQuery('fvCEp')
            q.subtree = 'children'
            tenantMo = moDir.query(q)
        except cobra.mit.request.QueryError as e:
            log('Reason: ' + e.reason)
            log('Error: ' + e.error)
            log('HTTP code: ' + e.httpCode)
            log(traceback.format_exc())

        data = {}

        for mo in tenantMo:
            for child in mo.rscEpToPathEp:
                #print child.dn
                ip = mo.ip

                tn, ap, epg, cep, varPod, varStrPath, varStrPort = tDnToPath(child.dn)
                if 'protpaths' in child.tDn: portType = 'vPC'
                elif 'paths' in child.tDn and 'eth' in child.tDn: portType = '-'
                else: portType = 'PC'
                encap = (mo.encap).split('-')[1]

                #if args.macSearch: bd,ctx = getAncestorDnStrFromDnString(md, str(mo.dn), 1)
                #else: bd='-'; ctx='-'
                bd='-'; ctx='-'

                #row = (tn,ap,epg,cep,mo.ip,portType,varStrPath,varStrPort,varPod,encap,'%s:%s' %(bd,ctx))
                row = {
                    "tn": tn,
                    "ap/l2out":ap,
                    "epg":epg,
                    "cep":cep,
                    "ip":mo.ip,
                    "type":portType,
                    "path":varStrPath,
                    "port":varStrPort,
                    "pod":varPod,
                    "encap":encap,
                    "bd":"-:-"
                }
                tableList.append(row)

                #data[child.tDn]= row
        moDir.logout()
        #print json.dumps(data)
        #return render_template('home.html', table=tableList)
        #return respFormatJsonMos(data, len(data))
        log(tableList)
        reply = jsonify({'results': tableList})

    except Exception as e:
        log(traceback.format_exc())

    return reply
开发者ID:clakits,项目名称:ACI-CL,代码行数:77,代码来源:plugin_server.py


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