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


Python MoDirectory.commit方法代码示例

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


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

示例1: test_post_tn

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import commit [as 别名]
 def test_post_tn(self, apics, certobject, userobject):
     apic = apics[0]
     secure = False if apics[1] == 'False' else True
     userobject.pkey = certobject.readFile(
         fileName=certobject.pkeyfile)
     session = CertSession(apic, userobject.certDn, userobject.pkey,
                           secure=secure, requestFormat='xml')
     moDir = MoDirectory(session)
     uni = Uni('')
     fvTenant = Tenant(uni, name='t')
     fvBD = BD(fvTenant, 't-bd')
     fvAp = Ap(fvTenant, 't-app')
     cr = ConfigRequest()
     #cr.subtree = 'full'
     cr.addMo(fvTenant)
     if userobject.user == 'rouser':
         with pytest.raises(RestError) as excinfo:
             r = moDir.commit(cr)
         assert ((excinfo.value.reason == ('user rouser does not have ' +
                                           'domain access to config Mo, ' +
                                           'class fvTenant')) or
                 (excinfo.value.reason == ('user rouser does not have ' +
                                           'domain access to config Mo, ' +
                                           'class fvBD')))
     elif userobject.user == 'rwuser':
         r = moDir.commit(cr)
     else:
         raise NotImplementedError
开发者ID:bischatt78,项目名称:cobra,代码行数:30,代码来源:test_session_CertSession.py

示例2: APICHandler

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

示例3: main

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import commit [as 别名]
def main(host, username, password, pool_name, from_vlan, to_vlan):
    apic = "https://%s" % host
    print("Connecting to APIC : %s" % apic)
    moDir = MoDirectory(LoginSession(apic, username, password))
    moDir.login()
    topMO = moDir.lookupByDn('uni')
    moDir.lookupByDn
    infraInfra = cobra.model.infra.Infra(topMO)
    fvnsVlanInstP = VlanInstP(infraInfra,name=pool_name, allocMode="static")
    temp_from_vlan = "vlan-" + from_vlan
    temp_to_vlan = "vlan-" + to_vlan
    fvnsEncapBlk = EncapBlk(fvnsVlanInstP, temp_from_vlan, temp_to_vlan)

    print(toXMLStr(topMO))
    c = ConfigRequest()
    c.addMo(infraInfra)
    moDir.commit(c)
开发者ID:gent79reid,项目名称:ACI,代码行数:19,代码来源:create_vlan_pool.py

示例4: test_cleanup_user

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import commit [as 别名]
 def test_cleanup_user(self, apics, certobject, userobject):
     apic = apics[0]
     user = apics[2]
     password = apics[3]
     secure = False if apics[1] == 'False' else True
     userobject.aaaUser.delete()
     session = LoginSession(apic, user, password, secure=secure)
     moDir = MoDirectory(session)
     moDir.login()
     cr = ConfigRequest()
     cr.addMo(userobject.aaaUser)
     r = moDir.commit(cr)
     assert r == []
开发者ID:bischatt78,项目名称:cobra,代码行数:15,代码来源:test_session_CertSession.py

示例5: test_tn_cleanup

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import commit [as 别名]
 def test_tn_cleanup(self, apics, certobject, userobject):
     if userobject.user == 'rouser':
         return
     apic = apics[0]
     user = apics[2]
     password = apics[3]
     secure = False if apics[1] == 'False' else True
     uni = Uni('')
     fvTenant = Tenant(uni, name='t')
     fvTenant.delete()
     fvBD = BD(fvTenant, 't-bd')
     fvBD.delete()
     fvAp = Ap(fvTenant, 't-app')
     fvAp.delete()
     session = LoginSession(apic, user, password, secure=secure)
     moDir = MoDirectory(session)
     moDir.login()
     cr = ConfigRequest()
     cr.addMo(fvTenant)
     r = moDir.commit(cr)
     assert r == []
开发者ID:bischatt78,项目名称:cobra,代码行数:23,代码来源:test_session_CertSession.py

示例6: main

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import commit [as 别名]
def main(host, port, user, password):

    # CONNECT TO APIC
    print('Initializing connection to APIC...')
    apicUrl = 'http://%s:%d' % (host, port)
    moDir = MoDirectory(LoginSession(apicUrl, user, password))
    moDir.login()

    # Get the top level Policy Universe Directory
    uniMo = moDir.lookupByDn('uni')
    uniInfraMo = moDir.lookupByDn('uni/infra')

    # Create Vlan Namespace
    nsInfo = VMM_DOMAIN_INFO['namespace']
    print("Creating namespace %s.." % (nsInfo['name']))
    fvnsVlanInstPMo = VlanInstP(uniInfraMo, nsInfo['name'], 'dynamic')
    #fvnsArgs = {'from': nsInfo['from'], 'to': nsInfo['to']}
    EncapBlk(fvnsVlanInstPMo, nsInfo['from'], nsInfo['to'], name=nsInfo['name'])
    
    nsCfg = ConfigRequest()
    nsCfg.addMo(fvnsVlanInstPMo)
    moDir.commit(nsCfg)

    # Create VMM Domain
    print('Creating VMM domain...')

    vmmpVMwareProvPMo = moDir.lookupByDn('uni/vmmp-VMware')
    vmmDomPMo = DomP(vmmpVMwareProvPMo, VMM_DOMAIN_INFO['name'])
    
    vmmUsrMo = []
    for usrp in VMM_DOMAIN_INFO['usrs']:
        usrMo = UsrAccP(vmmDomPMo, usrp['name'], usr=usrp['usr'],
                        pwd=usrp['pwd'])
        vmmUsrMo.append(usrMo)

    # Create Controllers under domain
    for ctrlr in VMM_DOMAIN_INFO['ctrlrs']:
        vmmCtrlrMo = CtrlrP(vmmDomPMo, ctrlr['name'], scope=ctrlr['scope'],
                            hostOrIp=ctrlr['ip'])
        # Associate Ctrlr to UserP
        RsAcc(vmmCtrlrMo, tDn=vmmUsrMo[0].dn)
    
    # Associate Domain to Namespace
    RsVlanNs(vmmDomPMo, tDn=fvnsVlanInstPMo.dn)
   
    vmmCfg = ConfigRequest()
    vmmCfg.addMo(vmmDomPMo)
    moDir.commit(vmmCfg)
    print("VMM Domain Creation Completed.")

    print("Starting Tenant Creation..")
    for tenant in TENANT_INFO:
        print("Creating tenant %s.." % (tenant['name']))
        fvTenantMo = Tenant(uniMo, tenant['name'])
        
        # Create Private Network
        Ctx(fvTenantMo, tenant['pvn'])
        
        # Create Bridge Domain
        fvBDMo = BD(fvTenantMo, name=tenant['bd'])
        
        # Create association to private network
        RsCtx(fvBDMo, tnFvCtxName=tenant['pvn'])
        
        # Create Application Profile
        for app in tenant['ap']:
            print('Creating Application Profile: %s' % app['name'])
            fvApMo = Ap(fvTenantMo, app['name'])
            
            # Create EPGs 
            for epg in app['epgs']:
                
                print("Creating EPG: %s..." % (epg['name'])) 
                fvAEPgMo = AEPg(fvApMo, epg['name'])
                
                # Associate EPG to Bridge Domain 
                RsBd(fvAEPgMo, tnFvBDName=tenant['bd'])
                # Associate EPG to VMM Domain
                RsDomAtt(fvAEPgMo, vmmDomPMo.dn)

        # Commit each tenant seperately
        tenantCfg = ConfigRequest()
        tenantCfg.addMo(fvTenantMo)
        moDir.commit(tenantCfg)
    print('All done!')
开发者ID:bischatt78,项目名称:cobra,代码行数:87,代码来源:tenants.py

示例7: LoginSession

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import commit [as 别名]
from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession
from cobra.model.fv import Ctx
from cobra.model.fv import *
from cobra.mit.request import *

# APIC Login Credentials
apicUrl = 'https://URL-of-APIC'
loginSession = LoginSession(apicUrl, 'username', 'password')

# APIC Managed Object Directory - starting at the top
moDir = MoDirectory(loginSession)

# Program asks for the name of the tenant to be created
TenantName = raw_input("Tenant Name: ")

moDir.login()

# Create new Tenant 
uniMo = moDir.lookupByDn('uni')
fvTenantMo = Tenant(uniMo, TenantName)

# Create new Private network/VRF under the new Tenant
fvContextMo = Ctx(fvTenantMo, 'myVRF')

# Add the new Tenant and its VRF Configuration to the APIC and commit these changes
cfgRequest = ConfigRequest()
cfgRequest.addMo(fvTenantMo)
moDir.commit(cfgRequest)

moDir.logout()
开发者ID:bgosselin,项目名称:ACI-Python-Scripts,代码行数:33,代码来源:CobraSDK-HelloWorld.py

示例8: __init__

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

示例9: AEPg

# 需要导入模块: from cobra.mit.access import MoDirectory [as 别名]
# 或者: from cobra.mit.access.MoDirectory import commit [as 别名]
if __name__ == "__main__":

    # Enter tenant, application profile where VMM exists
    tenant = "infra"
    ap = "access"

    # Making a new epg and calling it "vmepg"
    application_profile = moDir.lookupByDn("uni/tn-{0}/ap-{1}".format(tenant, ap))

    new_epg = AEPg(application_profile, "vmepg")

    # Committing the changes
    config_request = ConfigRequest()
    config_request.addMo(new_epg)

    moDir.commit(config_request)

    # Enter epg to use as template for vmepg
    epg_template= "default"

    dnQuery = DnQuery('uni/tn-{0}/ap-{1}/epg-{2}'.format(tenant, ap, epg_template))
    dnQuery.subtree = 'children'
    epgMO = moDir.query(dnQuery)

    # Traversing every property within epg_template and copying it to vmepg
    for epg in epgMO:
        for epgChild in epg.children:
            for name, obj in inspect.getmembers(sys.modules[__name__]):
                if inspect.isclass(obj):
                    copy_of_property = str(epgChild.rn)
                    if (copy_of_property.lower().startswith(obj.__name__.lower())):
开发者ID:alisidd,项目名称:VMAutomate,代码行数:33,代码来源:VMAutomate.py


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