def create_vlan_pool(infra_infra, vlan, allocation_mode, vlan_range_from, vlan_range_to): """Create VLAN Pool, the policy definition for ID ranges used for VLAN encapsulation. """ fvns_vlaninstp = VlanInstP(infra_infra, vlan, allocation_mode) # Set up the VLAN range. fvns_encapblk = EncapBlk(fvns_vlaninstp, 'vlan-' + str(vlan_range_from), 'vlan-' + str(vlan_range_to))
def create_vlan_pool(modir, vlan_name, allocation_mode, vlan_range_from, vlan_range_to): # Query to the vlan pool collections. infra_infra = modir.lookupByDn('uni/infra') # Create a VLAN. fvns_vlaninstp = VlanInstP(infra_infra, vlan_name, allocation_mode) # Set up the VLAN range. fvns_encapblk = EncapBlk(fvns_vlaninstp, 'vlan-'+vlan_range_from, 'vlan-'+vlan_range_to) print toXMLStr(infra_infra, prettyPrint=True) commit_change(modir, infra_infra)
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)
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
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!')
def create_vxlan_pool(infra_infra, vxlan, vxlan_range_from, vxlan_range_to): """Create VXLAN Pool""" fvns_vxlaninstp = VxlanInstP(infra_infra, vxlan) # Set up the VXLAN range. fvns_encapblk = EncapBlk(fvns_vxlaninstp, 'vxlan-'+str(vxlan_range_from), 'vxlan-'+str(vxlan_range_to))