def create_application_profiles(): # Create the Application Profile for appProfile in appProfiles: aApp = AppProfile(appProfile['name'], theTenant) for epg in appProfile['epgs']: appEpg = EPG(epg['name'], aApp) appEpg.add_bd(theBD) appEpg.add_infradomain(theVmmDomain) for provided in epg['provide']: appEpg.provide(Contract(provided, theTenant)) for consumed in epg['consume']: appEpg.consume(Contract(consumed, theTenant)) if not push_to_APIC(): print ("Sorry for the error. I'll exit now.") sys.exit()
def create_application_profiles(): # Create the Application Profile for appProfile in appProfiles: aApp = AppProfile(appProfile['name'], theTenant) for epg in appProfile['epgs']: appEpg = EPG(epg['name'], aApp) appEpg.add_bd(theBD) appEpg.add_infradomain(theVmmDomain) for provided in epg['provide']: appEpg.provide(Contract(provided, theTenant)) for consumed in epg['consume']: appEpg.consume(Contract(consumed, theTenant)) if not push_to_APIC(): print("Sorry for the error. I'll exit now.") sys.exit()
def build_base(): global theTenant, pushing_svi, pushcount count = 0 pushcount = 0 # This creates the tenant, vrf, and bridge domain theTenant = Tenant(tenant) theVRF = Context(tenant + vrf_extension, theTenant) for svi in all_svi: pushing_svi = svi if svi.ip == None: continue if svi.name == None: current_svi.set_name("vlan_" + svi.number) theBD = BridgeDomain(svi.name + bd_extension, theTenant) theBD.add_context(theVRF) aSubnet = Subnet('VLAN', theBD) subnet = svi.ip + svi.mask aSubnet.set_addr(subnet) aSubnet.set_scope(subnet_scope) theBD.add_subnet(aSubnet) # push_to_APIC() aApp = AppProfile(appProfile, theTenant) # push_to_APIC() theEPG = EPG(svi.name, aApp) theEPG.add_bd(theBD) theEPG.add_infradomain(theVmmDomain) push_to_APIC() pushcount += 1 count += 1 rand = random.randint(10, 18) if count >= rand: print("--Number of SVIs created so far: {0}".format( str(pushcount))) count = 0
def build_base(): global theTenant, pushing_svi, pushcount count = 0 pushcount = 0 # This creates the tenant, vrf, and bridge domain theTenant = Tenant(tenant) theVRF = Context(tenant + vrf_extension, theTenant) for svi in all_svi: pushing_svi = svi if svi.ip == None: continue if svi.name == None: current_svi.set_name("vlan_" + svi.number) theBD = BridgeDomain(svi.name + bd_extension, theTenant) theBD.add_context(theVRF) aSubnet = Subnet('VLAN', theBD) subnet = svi.ip + svi.mask aSubnet.set_addr(subnet) aSubnet.set_scope(subnet_scope) theBD.add_subnet(aSubnet) # push_to_APIC() aApp = AppProfile(appProfile, theTenant) # push_to_APIC() theEPG = EPG(svi.name, aApp) theEPG.add_bd(theBD) theEPG.add_infradomain(theVmmDomain) push_to_APIC() pushcount += 1 count += 1 rand = random.randint(10,18) if count >= rand: print ("--Number of SVIs created so far: {0}".format(str(pushcount))) count = 0
def main(): # Setup or credentials and session description = ('Create 3 EPGs within the same Context, have them ' 'provide and consume contracts and attach them to ' 'a vmm domain.') creds = Credentials('apic', description) args = creds.get() # Login to APIC session = Session(args.url, args.login, args.password) session.login() # Get the virtual domain we are going to use vdomain = EPGDomain.get_by_name(session, vmmdomain) # Create the Tenant tenant = Tenant(this_tenant) # Create the Application Profile app = AppProfile(this_app, tenant) # Create the EPGs t1_epg = EPG(tier1_epg, app) t2_epg = EPG(tier2_epg, app) t3_epg = EPG(tier3_epg, app) # Create a Context and BridgeDomain # Place all EPGs in the Context and in the same BD context = Context(private_net, tenant) bd = BridgeDomain(bridge_domain, tenant) bd.add_context(context) t1_epg.add_bd(bd) t1_epg.add_infradomain(vdomain) t2_epg.add_bd(bd) t2_epg.add_infradomain(vdomain) t3_epg.add_bd(bd) ''' Define a contract with a single entry Additional entries can be added by duplicating the FilterEntry Push to APIC after each FilterEntry if it is not the last ''' contract1 = Contract('mysql-contract', tenant) entry1 = FilterEntry('SQL', applyToFrag='no', arpOpc='unspecified', dFromPort='3306', dToPort='3306', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract1) contract2 = Contract('app-contract', tenant) contract2.set_scope('application-profile') entry1 = FilterEntry('Flask', applyToFrag='no', arpOpc='unspecified', dFromPort='5000', dToPort='5000', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract2) tenant.push_to_apic(session) entry2 = FilterEntry('Flask2', applyToFrag='no', arpOpc='unspecified', dFromPort='5050', dToPort='5050', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract2) contract3 = Contract('web-contract', tenant) contract3.set_scope('application-profile') entry1 = FilterEntry('HTTPS', applyToFrag='no', arpOpc='unspecified', dFromPort='443', dToPort='443', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract3) # Provide the contract from 1 EPG and consume from the other t3_epg.provide(contract1) t2_epg.consume(contract1) t2_epg.provide(contract2) t1_epg.consume(contract2) t1_epg.provide(contract3) # Finally, push all this to the APIC # Cleanup (uncomment the next line to delete the config) # CAUTION: The next line will DELETE the tenant # tenant.mark_as_deleted() resp = tenant.push_to_apic(session) if resp.ok: # Print some confirmation print('The configuration was sucessfully pushed to the APIC.')
def main(): required = collect_required() # Setup or credentials and session description = ('Create 5 EPGs within the same Context, have them ' 'provide and consume the same contract so that they ' 'can communicate between eachother.') creds = Credentials('apic', description) args = creds.get() # Login to APIC session = Session(args.url, args.login, args.password) session.login() # Get the virtual domain we are going to use try: vdomain = EPGDomain.get_by_name(session,required[1]) except: print "There was an error using " + required[1] + " as the VMMDomain. Are you sure it exists?" exit() # Create the Tenant tenant = Tenant(required[0]) # Create the Application Profile app = AppProfile(this_app, tenant) # Create the EPGs t1_epg = EPG(tier1_epg, app) t2_epg = EPG(tier2_epg, app) t3_epg = EPG(tier3_epg, app) t4_epg = EPG(tier4_epg, app) t5_epg = EPG(tier5_epg, app) # Create a Context and BridgeDomain # Place all EPGs in the Context and in the same BD context = Context(private_net, tenant) bd = BridgeDomain(bridge_domain, tenant) bd.add_context(context) # Add all the IP Addresses to the bridge domain bd_subnet5 = Subnet(tier1_epg, bd) bd_subnet5.set_addr(tier1_subnet) bd_subnet5.set_scope(subnet_scope) bd.add_subnet(bd_subnet5) bd_subnet6 = Subnet(tier2_epg, bd) bd_subnet6.set_addr(tier2_subnet) bd_subnet6.set_scope(subnet_scope) bd.add_subnet(bd_subnet6) bd_subnet7 = Subnet(tier3_epg, bd) bd_subnet7.set_addr(tier3_subnet) bd_subnet7.set_scope(subnet_scope) bd.add_subnet(bd_subnet7) bd_subnet8 = Subnet(tier4_epg, bd) bd_subnet8.set_addr(tier4_subnet) bd_subnet8.set_scope(subnet_scope) bd.add_subnet(bd_subnet8) bd_subnet9 = Subnet(tier5_epg, bd) bd_subnet9.set_addr(tier5_subnet) bd_subnet9.set_scope(subnet_scope) bd.add_subnet(bd_subnet9) t1_epg.add_bd(bd) t1_epg.add_infradomain(vdomain) t2_epg.add_bd(bd) t2_epg.add_infradomain(vdomain) t3_epg.add_bd(bd) t3_epg.add_infradomain(vdomain) t4_epg.add_bd(bd) t4_epg.add_infradomain(vdomain) t5_epg.add_bd(bd) t5_epg.add_infradomain(vdomain) ''' Define a contract with a single entry Additional entries can be added by duplicating "entry1" ''' contract1 = Contract('allow_all', tenant) entry1 = FilterEntry('all', applyToFrag='no', arpOpc='unspecified', dFromPort='unspecified', dToPort='unspecified', etherT='unspecified', prot='unspecified', tcpRules='unspecified', parent=contract1) # All the EPGs provide and consume the contract t1_epg.consume(contract1) t1_epg.provide(contract1) t2_epg.consume(contract1) t2_epg.provide(contract1) t3_epg.consume(contract1) t3_epg.provide(contract1) t4_epg.consume(contract1) t4_epg.provide(contract1) t5_epg.consume(contract1) t5_epg.provide(contract1) # Finally, push all this to the APIC # Cleanup (uncomment the next line to delete the config) # CAUTION: The next line will DELETE the tenant # tenant.mark_as_deleted() resp = tenant.push_to_apic(session) if resp.ok: # Print some confirmation print('The configuration was sucessfully pushed to the APIC.') # Uncomment the next lines if you want to see the configuration # print('URL: ' + str(tenant.get_url())) # print('JSON: ' + str(tenant.get_json())) else: print resp print resp.text print('URL: ' + str(tenant.get_url())) print('JSON: ' + str(tenant.get_json()))
def main(): required = collect_required() # Setup or credentials and session description = ('Create 5 EPGs within the same Context, have them ' 'provide and consume the same contract so that they ' 'can communicate between eachother.') creds = Credentials('apic', description) args = creds.get() # Login to APIC session = Session(args.url, args.login, args.password) session.login() # Get the virtual domain we are going to use try: vdomain = EPGDomain.get_by_name(session, required[1]) except: print "There was an error using " + required[ 1] + " as the VMMDomain. Are you sure it exists?" exit() # Create the Tenant tenant = Tenant(required[0]) # Create the Application Profile app = AppProfile(this_app, tenant) # Create the EPGs t1_epg = EPG(tier1_epg, app) t2_epg = EPG(tier2_epg, app) t3_epg = EPG(tier3_epg, app) t4_epg = EPG(tier4_epg, app) t5_epg = EPG(tier5_epg, app) # Create a Context and BridgeDomain # Place all EPGs in the Context and in the same BD context = Context(private_net, tenant) bd = BridgeDomain(bridge_domain, tenant) bd.add_context(context) # Add all the IP Addresses to the bridge domain bd_subnet5 = Subnet(tier1_epg, bd) bd_subnet5.set_addr(tier1_subnet) bd_subnet5.set_scope(subnet_scope) bd.add_subnet(bd_subnet5) bd_subnet6 = Subnet(tier2_epg, bd) bd_subnet6.set_addr(tier2_subnet) bd_subnet6.set_scope(subnet_scope) bd.add_subnet(bd_subnet6) bd_subnet7 = Subnet(tier3_epg, bd) bd_subnet7.set_addr(tier3_subnet) bd_subnet7.set_scope(subnet_scope) bd.add_subnet(bd_subnet7) bd_subnet8 = Subnet(tier4_epg, bd) bd_subnet8.set_addr(tier4_subnet) bd_subnet8.set_scope(subnet_scope) bd.add_subnet(bd_subnet8) bd_subnet9 = Subnet(tier5_epg, bd) bd_subnet9.set_addr(tier5_subnet) bd_subnet9.set_scope(subnet_scope) bd.add_subnet(bd_subnet9) t1_epg.add_bd(bd) t1_epg.add_infradomain(vdomain) t2_epg.add_bd(bd) t2_epg.add_infradomain(vdomain) t3_epg.add_bd(bd) t3_epg.add_infradomain(vdomain) t4_epg.add_bd(bd) t4_epg.add_infradomain(vdomain) t5_epg.add_bd(bd) t5_epg.add_infradomain(vdomain) ''' Define a contract with a single entry Additional entries can be added by duplicating "entry1" ''' contract1 = Contract('allow_all', tenant) entry1 = FilterEntry('all', applyToFrag='no', arpOpc='unspecified', dFromPort='unspecified', dToPort='unspecified', etherT='unspecified', prot='unspecified', tcpRules='unspecified', parent=contract1) # All the EPGs provide and consume the contract t1_epg.consume(contract1) t1_epg.provide(contract1) t2_epg.consume(contract1) t2_epg.provide(contract1) t3_epg.consume(contract1) t3_epg.provide(contract1) t4_epg.consume(contract1) t4_epg.provide(contract1) t5_epg.consume(contract1) t5_epg.provide(contract1) # Finally, push all this to the APIC # Cleanup (uncomment the next line to delete the config) # CAUTION: The next line will DELETE the tenant # tenant.mark_as_deleted() resp = tenant.push_to_apic(session) if resp.ok: # Print some confirmation print('The configuration was sucessfully pushed to the APIC.') # Uncomment the next lines if you want to see the configuration # print('URL: ' + str(tenant.get_url())) # print('JSON: ' + str(tenant.get_json())) else: print resp print resp.text print('URL: ' + str(tenant.get_url())) print('JSON: ' + str(tenant.get_json()))
def main(): # Setup or credentials and session description = ('Create 3 EPGs within the same Context, have them ' 'provide and consume contracts and attach them to ' 'a vmm domain.') creds = Credentials('apic', description) args = creds.get() # Login to APIC session = Session(args.url, args.login, args.password) session.login() # Get the virtual domain we are going to use vdomain = EPGDomain.get_by_name(session,vmmdomain) # Create the Tenant tenant = Tenant(this_tenant) # Create the Application Profile app = AppProfile(this_app, tenant) # Create the EPGs t1_epg = EPG(tier1_epg, app) t2_epg = EPG(tier2_epg, app) t3_epg = EPG(tier3_epg, app) # Create a Context and BridgeDomain # Place all EPGs in the Context and in the same BD context = Context(private_net, tenant) bd = BridgeDomain(bridge_domain, tenant) bd.add_context(context) t1_epg.add_bd(bd) t1_epg.add_infradomain(vdomain) t2_epg.add_bd(bd) t2_epg.add_infradomain(vdomain) t3_epg.add_bd(bd) ''' Define a contract with a single entry Additional entries can be added by duplicating the FilterEntry Push to APIC after each FilterEntry if it is not the last ''' contract1 = Contract('mysql-contract', tenant) entry1 = FilterEntry('SQL', applyToFrag='no', arpOpc='unspecified', dFromPort='3306', dToPort='3306', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract1) contract2 = Contract('app-contract', tenant) contract2.set_scope('application-profile') entry1 = FilterEntry('Flask', applyToFrag='no', arpOpc='unspecified', dFromPort='5000', dToPort='5000', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract2) tenant.push_to_apic(session) entry2 = FilterEntry('Flask2', applyToFrag='no', arpOpc='unspecified', dFromPort='5050', dToPort='5050', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract2) contract3 = Contract('web-contract', tenant) contract3.set_scope('application-profile') entry1 = FilterEntry('HTTPS', applyToFrag='no', arpOpc='unspecified', dFromPort='443', dToPort='443', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract3) # Provide the contract from 1 EPG and consume from the other t3_epg.provide(contract1) t2_epg.consume(contract1) t2_epg.provide(contract2) t1_epg.consume(contract2) t1_epg.provide(contract3) # Finally, push all this to the APIC # Cleanup (uncomment the next line to delete the config) # CAUTION: The next line will DELETE the tenant # tenant.mark_as_deleted() resp = tenant.push_to_apic(session) if resp.ok: # Print some confirmation print('The configuration was sucessfully pushed to the APIC.')