def create_base():
    global theTenant, theBD
    # This creates the tenant, vrf, and bridge domain
    theTenant = Tenant(tenant)
    theVRF = Context(vrf, theTenant)
    theBD = BridgeDomain(bridge_domain, theTenant)
    theBD.add_context(theVRF)

    for ipSubnet in ipSubnets:
        aSubnet = Subnet('VLAN', theBD)
        aSubnet.set_addr(ipSubnet)
        aSubnet.set_scope(subnet_scope)
        theBD.add_subnet(aSubnet)

    return
def create_base():
    global theTenant, theBD
    # This creates the tenant, vrf, and bridge domain
    theTenant = Tenant(tenant)
    theVRF = Context(vrf, theTenant)
    theBD = BridgeDomain(bridge_domain, theTenant)
    theBD.add_context(theVRF)

    for ipSubnet in ipSubnets:
        aSubnet = Subnet('VLAN', theBD)
        aSubnet.set_addr(ipSubnet)
        aSubnet.set_scope(subnet_scope)
        theBD.add_subnet(aSubnet)

    return
Example #3
0
def main():
    """
    Main execution routine

    :return: None
    """
    creds = Credentials('apic')
    creds.add_argument('--tenant', help='The name of Tenant')
    creds.add_argument('--vrf', help='The name of VRF')
    creds.add_argument('--bd', help='The name of BridgeDomain')
    creds.add_argument('--address', help='Subnet IPv4 Address')
    creds.add_argument('--scope', help='The scope of subnet ("public", "private", "shared", "public,shared", "private,shared", "shared,public", "shared,private")')
    creds.add_argument('--json', const='false', nargs='?', help='Json output only')

    args = creds.get()
    session = Session(args.url, args.login, args.password)
    session.login()

    tenant = Tenant(args.tenant)
    vrf = Context(args.vrf)
    bd = BridgeDomain(args.bd, tenant)
    bd.add_context(vrf)

    if args.address is None:
        bd.set_arp_flood('yes')
        bd.set_unicast_route('no')
    else:
        bd.set_arp_flood('no')
        bd.set_unicast_route('yes')

        subnet = Subnet('', bd)
        subnet.addr = args.address

        if args.scope is None:
            subnet.set_scope("private")
        else:
            subnet.set_scope(args.scope)

    if args.json:
        print(tenant.get_json())
    else:
        resp = session.push_to_apic(tenant.get_url(),
                                    tenant.get_json())

        if not resp.ok:
            print('%% Error: Could not push configuration to APIC')
            print(resp.text)
Example #4
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
Example #5
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():
    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()))
Example #7
0
     bd_obj      = existing_tenants[tn]['bds'][bd]['object']
     bd_subnets  = existing_tenants[tn]['bds'][bd]['subnets']
 # We do nothing for BDs that don't exist on the target fabric
 except:
     warning(" |_ %s/%s does not exist on the target fabric. Skipping..." % (tn, bd))
     continue
 else:
     # Now we add all the GWs that we found on the input file. If they
     # already existed, we pull the existing object and update the 
     # parameters, just in case something like the scope changed.
     if sn not in bd_subnets:
         output(" |_ Subnet %s/%s/%s did not exist and will be added." % (tn, bd, sn))
         subnet = Subnet("", bd_obj)
         subnet.set_addr(sn)
         bd_obj.add_subnet(subnet)
         subnet.set_scope(scope)
     else:
         output(" |_ Subnet %s/%s/%s already exists on the fabric." % (tn, bd, sn))
         subnet = bd_subnets[sn]
         if subnet.get_scope() != scope:
             subnet.set_scope(scope)
             output("   |_ Subnet scope will be updated to '%s'" % scope)
     
     if bd_obj.get_unknown_mac_unicast() != flood_uni:
         bd_obj.set_unknown_mac_unicast(flood_uni)
         output("   |_ Unicast flooding will be updated to '%s'" % flood_uni)
     if bd_obj.get_unknown_multicast() != flood_multi:
         bd_obj.set_unknown_multicast(flood_multi)
         output("   |_ Multicast flooding will be updated to '%s'" % flood_uni)
     if bd_obj.get_arp_flood() != flood_arp:
         bd_obj.set_arp_flood(flood_arp)
Example #8
0
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()))