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
示例#2
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
示例#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)
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
示例#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()))
示例#7
0
    else:
        output("[+] Successfully connected to %s" % args.url)
    
    # First of all, let's retrieve a bunch of data from the fabric we connected to
    existing_tenants = {}
    tenants_modified = {}
    tenants = Tenant.get(session)
    print("[+] Objects discovered on the current fabric '%s'" % args.url)
    for t in tenants:
        print(" |_ Tenant '%s'" % t.name)
        existing_tenants[t.name]={'object': t, 'bds':{}}
        bds = BridgeDomain.get(session, t)
        for b in bds:
            print(" |  |_ BD '%s'" % b.name)
            existing_tenants[t.name]['bds'][b.name]={'object':b, 'subnets':{}}
            subnets = Subnet.get(session, b, t)
            for s in subnets:
                existing_tenants[t.name]['bds'][b.name]['subnets'][s.get_addr()]=s
                print(" |  |  |_ GW '%s'" % s.get_addr())
               
    # Now, let's read the input file and for each GW, update the config on 
    # the fabric
    f = open(args.input, "r")
    input_tenants={}
    print("[+] Changes to be applied to the current fabric '%s'" % args.url)
    for gw_info in csv.DictReader(f):

        # Store info in simpler variables
        tn = gw_info['tenant-name']
        bd = gw_info['bd-name']
        sn = gw_info['bd-subnet-addr']
示例#8
0
    # Fetch existing Tenants and Bridge Domains
    tenants = Tenant.get(session)
    for t in tenants:
        
        # Filter out tenants if user passed --filter <tenant_name>
        if args.filter is not None:
            if t.name != args.filter:
                continue
        
        print("[+] Discovered Tenant '%s'" % t.name)
        tenants_db[t.name]={'object': t, 'bds':{}}
        bds = BridgeDomain.get(session, t)
        for b in bds:
            print(" |_ BD '%s'" % b.name)
            tenants_db[t.name]['bds'][b.name]={'object':b, 'subnets':{}}
            subnets = Subnet.get(session, b, t)
            for s in subnets:
                tenants_db[t.name]['bds'][b.name]['subnets'][s.get_addr()]=s
                print("   |_ Subnet '%s'" % s.get_addr())
                f.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % 
                                          (t.name, b.name, b.get_mac(), 
                                           b.get_unknown_mac_unicast(),
                                           b.get_unknown_multicast(),
                                           b.get_arp_flood(),
                                           b.get_unicast_route(), 
                                           s.get_addr(),
                                           s.get_scope().replace(",", "|"),
                                           s.name))

    f.close()
    output("[+] Results written successfully to %s" % args.output)
示例#9
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()))