How to use the cobra.mit 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 / 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
# 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.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')
github datacenter / ACI / arya / arya / getconfigfromapic.py View on Github external
'-s', '--secure', help='Verify certificate', default=False)
    parser.add_argument(
        '-pw', '--password', help='APIC Password', required=True)
    parser.add_argument('-d', '--dn', help='DN to query', required=True)
    parser.add_argument(
        '-v', '--verbose', help='Enable debugging', default=False)
    args = parser.parse_args()

    if args.verbose:
        httplib.HTTPConnection.debuglevel = 1
        logging.basicConfig(level=logging.DEBUG)

    if args.endpoint:
        ep = cobra.mit.access.EndPoint(
            args.apic, secure=False if args.port == 80 else True, port=args.port)
        ls = cobra.mit.session.LoginSession(args.user, args.password)
        md = cobra.mit.access.MoDirectory(ep, ls)
    else:
        if args.apic.startswith(('http://', 'https://')):
            if args.apic.endswith('/'):
                args.apic = args.apic[:-1]
            args.apic = str(args.apic) + ":" + str(args.port) + "/"
            ls = cobra.mit.session.LoginSession(
                args.apic, args.user, args.password, secure=args.secure)
            md = cobra.mit.access.MoDirectory(ls)
    md.login()

    mo = lookupSubtreeByDn(md, args.dn)
    if mo:
        xmlstr = toXMLStr(mo, includeAllProps=True, prettyPrint=True)
        print arya().getpython(xmlstr=xmlstr, apicip=args.apic, apicuser=args.user, apicpassword=args.password)
    else:
github datacenter / arya / arya / getconfigfromapic.py View on Github external
if args.verbose:
        http.client.HTTPConnection.debuglevel = 1
        logging.basicConfig(level=logging.DEBUG)

    if args.endpoint:
        ep = cobra.mit.access.EndPoint(
            args.apic, secure=False if args.port == 80 else True, port=args.port)
        ls = cobra.mit.session.LoginSession(args.user, args.password)
        md = cobra.mit.access.MoDirectory(ep, ls)
    else:
        if args.apic.startswith(('http://', 'https://')):
            if args.apic.endswith('/'):
                args.apic = args.apic[:-1]
            args.apic = str(args.apic) + ":" + str(args.port) + "/"
            ls = cobra.mit.session.LoginSession(
                args.apic, args.user, args.password, secure=args.secure)
            md = cobra.mit.access.MoDirectory(ls)
    md.login()

    mo = lookupSubtreeByDn(md, args.dn)
    if mo:
        xmlstr = toXMLStr(mo, includeAllProps=True, prettyPrint=True)
        print(arya().getpython(xmlstr=xmlstr, apicip=args.apic, apicuser=args.user, apicpassword=args.password))
    else:
        print('Nothing found for DN {0}'.format(args.dn))
github datacenter / ACI / arya / arya / getconfigfromapic.py View on Github external
def lookupSubtreeByDn(md, dn, propFilter=None):
    dnq = cobra.mit.request.DnQuery(dn)
    dnq.subtree = 'full'
    dnq.propInclude = 'config-only'
    if propFilter:
        dnq.propFilter = propFilter
    try:
        return md.query(dnq)[0]
    except:
        return None
github datacenter / arya / arya / getconfigfromapic.py View on Github external
parser.add_argument(
        '-pw', '--password', help='APIC Password', required=True)
    parser.add_argument('-d', '--dn', help='DN to query', required=True)
    parser.add_argument(
        '-v', '--verbose', help='Enable debugging', default=False)
    args = parser.parse_args()

    if args.verbose:
        http.client.HTTPConnection.debuglevel = 1
        logging.basicConfig(level=logging.DEBUG)

    if args.endpoint:
        ep = cobra.mit.access.EndPoint(
            args.apic, secure=False if args.port == 80 else True, port=args.port)
        ls = cobra.mit.session.LoginSession(args.user, args.password)
        md = cobra.mit.access.MoDirectory(ep, ls)
    else:
        if args.apic.startswith(('http://', 'https://')):
            if args.apic.endswith('/'):
                args.apic = args.apic[:-1]
            args.apic = str(args.apic) + ":" + str(args.port) + "/"
            ls = cobra.mit.session.LoginSession(
                args.apic, args.user, args.password, secure=args.secure)
            md = cobra.mit.access.MoDirectory(ls)
    md.login()

    mo = lookupSubtreeByDn(md, args.dn)
    if mo:
        xmlstr = toXMLStr(mo, includeAllProps=True, prettyPrint=True)
        print(arya().getpython(xmlstr=xmlstr, apicip=args.apic, apicuser=args.user, apicpassword=args.password))
    else:
        print('Nothing found for DN {0}'.format(args.dn))
github datacenter / arya / arya / getconfigfromapic.py View on Github external
def lookupSubtreeByDn(md, dn, propFilter=None):
    dnq = cobra.mit.request.DnQuery(dn)
    dnq.subtree = 'full'
    dnq.propInclude = 'config-only'
    if propFilter:
        dnq.propFilter = propFilter
    try:
        return md.query(dnq)[0]
    except:
        return None
github datacenter / arya / arya / getconfigfromapic.py View on Github external
parser.add_argument('-u', '--user', help='APIC Username', default='admin')
    parser.add_argument(
        '-s', '--secure', help='Verify certificate', default=False)
    parser.add_argument(
        '-pw', '--password', help='APIC Password', required=True)
    parser.add_argument('-d', '--dn', help='DN to query', required=True)
    parser.add_argument(
        '-v', '--verbose', help='Enable debugging', default=False)
    args = parser.parse_args()

    if args.verbose:
        http.client.HTTPConnection.debuglevel = 1
        logging.basicConfig(level=logging.DEBUG)

    if args.endpoint:
        ep = cobra.mit.access.EndPoint(
            args.apic, secure=False if args.port == 80 else True, port=args.port)
        ls = cobra.mit.session.LoginSession(args.user, args.password)
        md = cobra.mit.access.MoDirectory(ep, ls)
    else:
        if args.apic.startswith(('http://', 'https://')):
            if args.apic.endswith('/'):
                args.apic = args.apic[:-1]
            args.apic = str(args.apic) + ":" + str(args.port) + "/"
            ls = cobra.mit.session.LoginSession(
                args.apic, args.user, args.password, secure=args.secure)
            md = cobra.mit.access.MoDirectory(ls)
    md.login()

    mo = lookupSubtreeByDn(md, args.dn)
    if mo:
        xmlstr = toXMLStr(mo, includeAllProps=True, prettyPrint=True)
github datacenter / who-moved-my-cli / NexusConfigToEPGasVLAN.py View on Github external
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 / sbx-intermediate-aci / sbx-intermediate-aci-mission1_health-dashboard / dashboard / app / views_SOLUTION.py View on Github external
def aci_login():
    auth = cobra.mit.session.LoginSession(URL, LOGIN, PASSWORD)
    session = cobra.mit.access.MoDirectory(auth)
    session.login()

    return session