示例#1
0
def switch_profile(host, user, password, if_profile):

    print('[BEG] Switch Profile Configuration')
    moDir = apic_login(host, user, password)

    # Get Top Level Objects
    polUni = Uni('')
    infraInfra = Infra(polUni)

    #Create Variables to be used later

    sPName = 'ASA-VPC-1-Cobra'
    swSelName = 'L103-104-ASA-VPC'
    LFrom = '103'
    LTo = '104'
    ifProfName = if_profile
    nodeBlkName = 'somethingsomethingnodeBlk'
    print('--- Creating Switch Profile: ' + sPName)
    infraNodeP = NodeP(infraInfra, ownerKey=u'', name=sPName)

    print('	Adding Switch Selector: ' + swSelName + ' with Nodes :' + LFrom +
          ',' + LTo)
    infraLeafS = LeafS(infraNodeP, ownerKey=u'', type=u'range', name=swSelName)
    infraNodeBlk = NodeBlk(infraLeafS, from_=LFrom, name=nodeBlkName, to_=LTo)

    print('	Adding Interface Selector Profile: ' + ifProfName)
    infraRsAccPortP = RsAccPortP(infraNodeP,
                                 tDn=u'uni/infra/accportprof-' + ifProfName)

    # Commit Configuration
    cfg_commit(moDir, infraInfra)
    print('[END] Switch Profile Configuration \n')
示例#2
0
def AEP_attach(host, user, password, policy, AEP):
    print('[BEG] Applying ' + AEP + ' to Interface Policy: ' + policy)
    moDir = apic_login(host, user, password)

    polUni = Uni('')
    infraInfra = Infra(polUni)
    infraFuncP = FuncP(infraInfra)

    ifPG_Name = 'ASA-Port-Policy-VPC-Cobra'

    infraAccBndlGrp = AccBndlGrp(infraFuncP, name=ifPG_Name, lagT=u'node')
    infraRsAttEntP = RsAttEntP(infraAccBndlGrp,
                               tDn=u'uni/infra/attentp-' + AEP)

    cfg_commit(moDir, infraFuncP)
    print('[END] Successful AEP Attach')
示例#3
0
def int_profile(host, user, password, port_policy):

    print('[BEG] Port Profile Configuration')
    moDir = apic_login(host, user, password)

    # Get Top Level Objects
    polUni = Uni('')
    infraInfra = Infra(polUni)

    # Variables to keep Ports Consistent
    intPName = 'ASA-VPC-INT-PROFILE-Cobra'
    pSPortP = port_policy
    pSFexId = '101'
    pS1 = '15'
    pS2 = '16'

    # Port Selector Variables #1 - to be used later for other method of input

    pSName = 'ASA_VPC_Port_Range_' + pS1 + '_to_' + pS2 + '-Cobra'

    # Port Selector Variables #2 - to be used later for other method of input

    print('--- Creating Port Profile ' + intPName)
    infraAccPortP = AccPortP(infraInfra, name=intPName)

    print('	Adding ' + pSName + ' to Profile: ' + intPName)
    infraHPortS = HPortS(infraAccPortP, type=u'range', name=pSName)
    infraRsAccBaseGrp = RsAccBaseGrp(infraHPortS,
                                     fexId=pSFexId,
                                     tDn=u'uni/infra/funcprof/accbundle-' +
                                     pSPortP)
    infraPortBlk = PortBlk(infraHPortS,
                           name=u'block2',
                           fromPort=pS1,
                           fromCard=u'1',
                           toPort=pS1,
                           toCard=u'1')
    infraPortBlk2 = PortBlk(infraHPortS,
                            name=u'block3',
                            fromPort=pS2,
                            fromCard=u'1',
                            toPort=pS2,
                            toCard=u'1')

    cfg_commit(moDir, infraInfra)
    print('[END] Port Profile Configuration \n')
    return intPName
示例#4
0
def AEP_build(host, user, profile, domain):
    print('[BEG] Attached Entity Profile Configuration')
    moDir = apic_login(host, user, password)

    polUni = Uni('')
    infraInfra = Infra(polUni)

    aepName = 'ASA-L3OUT-Cobra'
    print('--- Creating AEP: ' + aepName)
    infraAttEntityP = AttEntityP(infraInfra, name=aepName)

    print('	Associating Domain: ' + domain + ' to AEP: ' + aepName)
    infraRsDomP2 = RsDomP(infraAttEntityP, tDn=u'uni/phys-' + domain + '-1')

    cfg_commit(moDir, infraInfra)
    print('[END] Attached Entity Profile Configuration')
    return aepName
示例#5
0
def if_policyG(host, user, password):
    print('[BEG] Interface Policy Group Creation')
    moDir = apic_login(host, user, password)

    polUni = Uni('')
    infraInfra = Infra(polUni)
    infraFuncP = FuncP(infraInfra)

    ifPG_Name = 'ASA-Port-Policy-VPC-Cobra'
    lldp_pol = 'LLDP-Enabled-Cobra'
    cdp_pol = 'CDP-Enabled-Cobra'
    mcp_pol = 'MCP-Enabled-Cobra'
    if_pol = '1GE-SFP-Cobra'
    lag_pol = 'LACP-Active-Cobra'

    print('--- Creating Policy Group Name: ' + ifPG_Name)
    infraAccBndlGrp = AccBndlGrp(infraFuncP, name=ifPG_Name, lagT=u'node')

    print('	Applying LLDP Policy: ' + lldp_pol)
    infraRsLldpIfPol = RsLldpIfPol(infraAccBndlGrp, tnLldpIfPolName=lldp_pol)

    print('	Applying CDP Policy: ' + cdp_pol)
    infraRsCdpIfPol = RsCdpIfPol(infraAccBndlGrp, tnCdpIfPolName=cdp_pol)

    print('	Applying MCP Policy: ' + mcp_pol)
    infraRsMcpIfPol = RsMcpIfPol(infraAccBndlGrp, tnMcpIfPolName=mcp_pol)

    print('	Applying Link Policy: ' + if_pol)
    infraRsHIfPol = RsHIfPol(infraAccBndlGrp, tnFabricHIfPolName=if_pol)

    print('	Applying LAG Policy: ' + lag_pol)
    infraRsLacpPol = RsLacpPol(infraAccBndlGrp,
                               tnLacpLagPolName=u'LACP-Active-Cobra')

    cfg_commit(moDir, infraFuncP)
    print('[END] Interface Policy Group Creation \n')
    return ifPG_Name
示例#6
0
def vlan_pool(host, user, password):
    print('[BEG] VLAN Pool Creation')
    moDir = apic_login(host, user, password)

    # Get Top Level Objects
    polUni = Uni('')
    infraInfra = Infra(polUni)

    vlanPName = 'ASA-L3-OUT-STATIC-Cobra'
    vlanMode = 'static'
    vlanTo = 'vlan-182'
    vlanFrom = 'vlan-181'

    print('--- Creating VLAN Pool: ' + vlanPName)
    fvnsVlanInstP = VlanInstP(infraInfra, name=vlanPName, allocMode=vlanMode)
    print('	Adding ' + vlanMode + ' pool from ' + vlanFrom + ' to ' + vlanTo)
    fvnsEncapBlk = EncapBlk(fvnsVlanInstP,
                            to=vlanTo,
                            from_=vlanFrom,
                            allocMode=vlanMode)

    cfg_commit(moDir, infraInfra)
    print('[END] VLAN Pool Creation \n')
    return vlanPName
示例#7
0
def infra_policy(host, user, password):
    moDir = apic_login(host, user, password)

    polUni = Uni('')
    infraInfra = Infra(polUni)

    # Create Link Level Policies for Fabric
    print('-- Creating Link Level Policies:')
    print('	10G Interface')
    fabric10GPol = HIfPol(infraInfra,
                          name=u'10GE-SFP-Cobra',
                          fecMode=u'inherit',
                          autoNeg=u'on',
                          speed=u'10G',
                          linkDebounce=u'100')
    print('	1G Interface')
    fabric1GPol = HIfPol(infraInfra,
                         name=u'1GE-SFP-Cobra',
                         fecMode=u'inherit',
                         autoNeg=u'on',
                         speed=u'1G',
                         linkDebounce=u'100')
    print('	FE Interface')
    fabricFEPol = HIfPol(infraInfra,
                         name=u'FE-SFP-Cobra',
                         fecMode=u'inherit',
                         autoNeg=u'on',
                         speed=u'100M',
                         linkDebounce=u'100')

    # Create CDP Policies for Fabric
    print('--- Creating CDP Policies:')
    print('	CDP Enabled')
    cdpIfPolEnabled = cdpIfPol.IfPol(infraInfra,
                                     name=u'CDP-Enabled-Cobra',
                                     adminSt=u'enabled')
    print('	CDP Disabled')
    cdpIfPolDisabled = cdpIfPol.IfPol(infraInfra,
                                      name=u'CDP-Disabled-Cobra',
                                      adminSt=u'disabled')

    # Create LLDP Policies for Fabric
    print('--- Creating LLDP Policies:')
    print('	LLDP Enabled')
    lldpIfPolEnabled = lldpIfPol.IfPol(infraInfra,
                                       name=u'LLDP-Enabled-Cobra',
                                       adminTxSt=u'enabled',
                                       adminRxSt=u'enabled')
    print('	LLDP Disabled')
    lldpIfPolDisabled = lldpIfPol.IfPol(infraInfra,
                                        name=u'LLDP-Disabled-Cobra',
                                        adminTxSt=u'disabled',
                                        adminRxSt=u'disabled')

    # Create LAG Policies for Fabric
    print('--- Creating LAG Policies:')
    print('	LACP Active')
    lacpLagPolLACP = LagPol(
        infraInfra,
        name=u'LACP-Active-Cobra',
        minLinks=u'1',
        ctrl=u'fast-sel-hot-stdby,graceful-conv,susp-individual',
        maxLinks=u'16',
        mode=u'active')
    print('	MAC Pinning')
    lacpLagPolMACPIN = LagPol(
        infraInfra,
        name=u'MAC-PIN-Cobra',
        minLinks=u'1',
        ctrl=u'fast-sel-hot-stdby,graceful-conv,susp-individual',
        maxLinks=u'16',
        mode=u'mac-pin')

    # Create MCP Policies - disable needed?
    print('--- Creating MCP Policies:')
    print('	MCP Enabled')
    mcpIfPolEnabled = mcpIfPol.IfPol(infraInfra,
                                     name=u'MCP-Enabled-Cobra',
                                     descr=u'Enable Mis-Cabling Protocol',
                                     adminSt=u'enabled')
    print('	MDP Disabled')
    mcpIfPolDisabled = mcpIfPol.IfPol(infraInfra,
                                      name=u'MCP-Disabled-Cobra',
                                      descr=u'Disable Mis-Cabling Protocol',
                                      adminSt=u'disabled')

    cfg_commit(moDir, infraInfra)
    print('[END] Infrastructure Policies \n')
示例#8
0
    node = re.search('node-(\d+)', dn)
    return node.group(1)


session = LoginSession(cred.URL, cred.LOGIN, cred.PASSWORD)
moDir = MoDirectory(session)
moDir.login()
uniMo = moDir.lookupByDn('uni')

lldpAdjEps = moDir.lookupByClass('lldpAdjEp')
if lldpAdjEps:
    print "Found adjacent hosts via LLDP:"
for adjEp in lldpAdjEps:
    print str(adjEp.dn) + " is connected to " + str(adjEp.sysName)

infraInfra = Infra(uniMo)

for adjEp in lldpAdjEps:
    if is_leaf(str(adjEp.dn)):
        infraHPathS = HPathS(infraInfra,
                             name="adjEp-{0}-{1}".format(
                                 str(adjEp.sysName),
                                 get_node_name(str(adjEp.dn))),
                             descr=str(adjEp.sysName))
        infraRsHPathAtt = RsHPathAtt(infraHPathS,
                                     tDn=concat_path_ep(str(adjEp.dn)))
    else:
        infraSHPathS = SHPathS(infraInfra,
                               name="adjEp-{0}-{1}".format(
                                   str(adjEp.sysName),
                                   get_node_name(str(adjEp.dn))),