How to use the cobra.mit.access.MoDirectory function in cobra

To help you get started, we’ve selected a few cobra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datacenter / cobra / tests / rest / test_rest.py View on Github external
def test_login_get_timeout(self, apic):
        """
        verify that the session times out properly
        """
        url, user, password, secure = apic
        secure = False if secure == 'False' else True
        session = cobra.mit.session.LoginSession(url, user, password,
                                                 secure=secure)
        moDir = cobra.mit.access.MoDirectory(session)
        moDir.login()

        assert moDir._session.refreshTime > int(time.time())
        assert moDir._session.refreshTimeoutSeconds > 0
github datacenter / cobra / tests / rest / test_rest.py View on Github external
def test_login_timeout(self, apic):
        """
        verify that the session times out properly
        """
        url, user, password, secure = apic
        secure = False if secure == 'False' else True
        session = cobra.mit.session.LoginSession(url, user, password,
                                                 secure=secure)
        moDir = cobra.mit.access.MoDirectory(session)
        moDir.login()
        start = time.time()

        pki = moDir.lookupByDn('uni/userext/pkiext/webtokendata')
        refreshTime = pki.webtokenTimeoutSeconds
        sleepTime = float(refreshTime) - (time.time() - start)
        sleepTime += 1.0  # one second buffer, for good measure

        time.sleep(sleepTime)

        with pytest.raises(cobra.mit.request.QueryError):
            moDir.lookupByClass('pkiWebTokenData')
github datacenter / cobra / tests / model / test_model.py View on Github external
def moDir(request):
    url, user, password, secure = request.param
    secure = False if secure == 'False' else True
    session = cobra.mit.session.LoginSession(url, user, password,
                                             secure=secure)
    md = cobra.mit.access.MoDirectory(session)
    md.login()
    return md
github joezersk / aci-multipod / mpod-base.py View on Github external
import cobra.mit.access
import cobra.mit.request
import cobra.mit.session
import cobra.model.bgp
import cobra.model.ctrlr
import cobra.model.dbg
import cobra.model.fabric
import cobra.model.fv
import cobra.model.l3ext
import cobra.model.ospf
import cobra.model.pol
from cobra.internal.codec.xmlcodec import toXMLStr

# log into an APIC and create a directory object
ls = cobra.mit.session.LoginSession('https://1.1.1.1', 'admin', 'cisco123')
md = cobra.mit.access.MoDirectory(ls)
md.login()

# the top level object on which operations will be made
topMo = cobra.model.pol.Uni('')

# build the request using cobra syntax
fabricInst = cobra.model.fabric.Inst(topMo)
dbgOngoingAcMode = cobra.model.dbg.OngoingAcMode(fabricInst, mode='path', name='default')

c = cobra.mit.request.ConfigRequest()
c.addMo(fabricInst)
md.commit(c)

fvTenant = cobra.model.fv.Tenant(topMo, name='infra')
fvFabricExtConnP = cobra.model.fv.FabricExtConnP(fvTenant, rt='extended:as2-nn4:11:22', id='1', name='fabricExtConnPolName_9a92763eadbe259d')
fvPodConnP = cobra.model.fv.PodConnP(fvFabricExtConnP, id='2')
github datacenter / who-moved-my-cli / NexusConfigToEPGasVLAN.py View on Github external
logging.basicConfig(format='%(asctime)s %(message)s',
                            datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.DEBUG)

    nodes = map(int, expandRange(nodes))

    print 'Parsing {0}'.format(args.config)
    nxosConf = NxosConfig(args.config)
    nxosVlanInts = nxosConf.getVlanIP()
    if len(nxosVlanInts) > 0:
        print 'Found {0} VLANs in configuration'.format(len(nxosVlanInts))
        vlans = []
        for svi in nxosVlanInts:
            vlans.append(tuple(svi))

        print 'Logging into APIC {0}'.format(apicUri)
        moDir = cobra.mit.access.MoDirectory(
            cobra.mit.session.LoginSession(apicUri, apicUser, apicPassword))
        easv = EPGasVLAN(md=moDir)
        print 'Creating EPGs'
        tenant,successfulnodes,successfulvlans = easv.createVlans(args.tenant, vlans, nodes)
        print 'Created:'
        print '  Tenant:    {0}'.format(args.tenant)
        print '  VLANS:     {0}'.format(', '.join([str(vlan) for vlan in successfulvlans]))
        print '  on Nodes:  {0}'.format(', '.join([str(node) for node in successfulnodes]))
    else:
        print 'No parsable SVI configuration found'
github CiscoDevNet / aci-learning-labs-code-samples / apic_fabric_setup / create_snv_apps.py View on Github external
def main():
	print("Setting up SnV Tenant")
	auth = cobra.mit.session.LoginSession(URL, LOGIN, PASSWORD)
	session = cobra.mit.access.MoDirectory(auth)
	session.login()

	root = cobra.model.pol.Uni('')

	tenant_snv = cobra.model.fv.Tenant(root, 'SnV')
	vrf_snv = cobra.model.fv.Ctx(tenant_snv, name='Superverse')
	bd_snv = cobra.model.fv.BD(tenant_snv, name='antigravity')
	bd_snv_vrf = cobra.model.fv.RsCtx(bd_snv, tnFvCtxName='Superverse')
	bd_snv_subnet = cobra.model.fv.Subnet(bd_snv, ip='10.2.10.1/23')

	contracts = (('web', 'http', 'tcp', '80', 'context'), ('database', 'sql', 'tcp', '1433', 'application-profile'))
	for contract in contracts:
		create_contract(tenant_snv, contract[1], contract[2], contract[3], contract[0], contract[4])

	app_names = (('Evolution_X', 'vlan-121', 'vlan-122'),
				 ('Rescue', 'vlan-123', 'vlan-124'),
github CiscoDevNet / aci-learning-labs-code-samples / sbx-intermediate-aci / sbx-intermediate-aci-mission0_build-a-tenant / evolution_x_SOLUTION.py View on Github external
#!/usr/bin/env python

# list of packages that should be imported for this code to work
import cobra.mit.access
import cobra.mit.request
import cobra.mit.session
import cobra.model.fv
import cobra.model.pol
import cobra.model.vz
from cobra.internal.codec.xmlcodec import toXMLStr

# log into an APIC and create a directory object
ls = cobra.mit.session.LoginSession('https://sandboxapicdc.cisco.com', 'admin', 'ciscopsdt')
md = cobra.mit.access.MoDirectory(ls)
md.login()

# the top level object on which operations will be made
topMo = cobra.model.pol.Uni('')


# build the request using cobra syntax
fvTenant = cobra.model.fv.Tenant(topMo, name=u'SnV')
fvCtx = cobra.model.fv.Ctx(fvTenant, name=u'Superverse')
fvBD = cobra.model.fv.BD(fvTenant, name=u'antigravity')
fvRsCtx = cobra.model.fv.RsCtx(fvBD, tnFvCtxName=u'Superverse')
fvSubnet = cobra.model.fv.Subnet(fvBD, ip=u'10.2.10.1/23', name=u'Subnet')
vzFilter = cobra.model.vz.Filter(fvTenant, name=u'http')
vzEntry = cobra.model.vz.Entry(vzFilter, etherT=u'ip', prot=u'tcp', dFromPort=u'http', name=u'tcp-80', dToPort=u'http')
vzFilter2 = cobra.model.vz.Filter(fvTenant, name=u'https')
vzEntry2 = cobra.model.vz.Entry(vzFilter2, etherT=u'ip', prot=u'tcp', dFromPort=u'https', name=u'tcp-443', dToPort=u'https')
github datacenter / ACI / configuration-python / generic_code / apicPython / createMo.py View on Github external
def apic_login(self):
        """Login to APIC"""
        if not self.host.startswith(('http', 'https')):
            self.host = 'https://' + self.host
        lsess = LoginSession(self.host, self.user, self.password,
                             requestFormat="xml", secure=False)
        modir = MoDirectory(lsess)
        modir.login()
        self.modir = modir
github CiscoDevNet / aci-learning-labs-code-samples / sbx-intermediate-aci / sbx-intermediate-aci-02_cobra / cobra_tenant.py View on Github external
def main():
    """
    This function creates the new Tenant with a VRF, Bridge Domain and Subnet.
    """
    # create a session and define the root
    requests.packages.urllib3.disable_warnings()
    auth = cobra.mit.session.LoginSession(URL, LOGIN, PASSWORD)
    session = cobra.mit.access.MoDirectory(auth)
    session.login()

    root = cobra.model.pol.Uni('')

    # test if tenant name is already in use
    test_tenant(TENANT, session)

    # model new tenant configuration
    tenant = cobra.model.fv.Tenant(root, name=TENANT)
    vrf = cobra.model.fv.Ctx(tenant, name=VRF)
    bridge_domain = cobra.model.fv.BD(tenant, name=BRIDGEDOMAIN)
    attached_vrf = cobra.model.fv.RsCtx(bridge_domain, tnFvCtxName=VRF)
    subnet = cobra.model.fv.Subnet(bridge_domain, ip=GATEWAY, scope=SCOPE, name=SUBNETNAME)

    #submit the configuration to the apic and print a success message
    config_request = cobra.mit.request.ConfigRequest()