コード例 #1
0
def main():
    """ Create 2 EPGs within the same Context and have
        1 EPG provide a contract to the other EPG.
    """
    description = ('Create 2 EPGs within the same Context and have'
                   '1 EPG provide a contract to the other EPG.')
    creds = Credentials('apic', description)
    args = creds.get()

    # Create the Tenant
    tenant = Tenant('aci-toolkit-demo')

    # Create the Application Profile
    app = AppProfile('my-demo-app', tenant)

    # Create the EPGs
    web_epg = EPG('web-frontend', app)
    db_epg = EPG('database-backend', app)
    web_epg.set_intra_epg_isolation(False)
    db_epg.set_intra_epg_isolation(True)

    # Create a Context and BridgeDomain
    # Place both EPGs in the Context and in the same BD
    context = Context('VRF-1', tenant)
    bd = BridgeDomain('BD-1', tenant)
    bd.add_context(context)
    web_epg.add_bd(bd)
    db_epg.add_bd(bd)

    # Define a contract with a single entry
    contract = Contract('mysql-contract', tenant)
    entry1 = FilterEntry('entry1',
                         applyToFrag='no',
                         arpOpc='unspecified',
                         dFromPort='3306',
                         dToPort='3306',
                         etherT='ip',
                         prot='tcp',
                         sFromPort='1',
                         sToPort='65535',
                         tcpRules='unspecified',
                         parent=contract)

    # Provide the contract from 1 EPG and consume from the other
    db_epg.provide(contract)
    web_epg.consume(contract)

    # Login to APIC and push the config
    session = Session(args.url, args.login, args.password)
    session.login()
    
    # Cleanup (uncomment the next line to delete the config)
    #tenant.mark_as_deleted()
    resp = tenant.push_to_apic(session)

    if resp.ok:
        # Print what was sent
        print('Pushed the following JSON to the APIC')
        print('URL: ' + str(tenant.get_url()))
        print('JSON: ' + str(tenant.get_json()))
コード例 #2
0
def main():
    """ Create 2 EPGs within the same Context and have
        1 EPG provide a contract to the other EPG.
    """
    description = ('Create 2 EPGs within the same Context and have'
                   '1 EPG provide a contract to the other EPG.')
    creds = Credentials('apic', description)
    args = creds.get()

    # Create the Tenant
    tenant = Tenant('aci-toolkit-demo')

    # Create the Application Profile
    app = AppProfile('my-demo-app', tenant)

    # Create the EPGs
    web_epg = EPG('web-frontend', app)
    db_epg = EPG('database-backend', app)
    web_epg.set_intra_epg_isolation(False)
    db_epg.set_intra_epg_isolation(True)

    # Create a Context and BridgeDomain
    # Place both EPGs in the Context and in the same BD
    context = Context('VRF-1', tenant)
    bd = BridgeDomain('BD-1', tenant)
    bd.add_context(context)
    web_epg.add_bd(bd)
    db_epg.add_bd(bd)

    # Define a contract with a single entry
    contract = Contract('mysql-contract', tenant)
    entry1 = FilterEntry('entry1',
                         applyToFrag='no',
                         arpOpc='unspecified',
                         dFromPort='3306',
                         dToPort='3306',
                         etherT='ip',
                         prot='tcp',
                         sFromPort='1',
                         sToPort='65535',
                         tcpRules='unspecified',
                         parent=contract)

    # Provide the contract from 1 EPG and consume from the other
    db_epg.provide(contract)
    web_epg.consume(contract)

    # Login to APIC and push the config
    session = Session(args.url, args.login, args.password)
    session.login()

    # Cleanup (uncomment the next line to delete the config)
    #tenant.mark_as_deleted()
    resp = tenant.push_to_apic(session)

    if resp.ok:
        # Print what was sent
        print('Pushed the following JSON to the APIC')
        print('URL: ' + str(tenant.get_url()))
        print('JSON: ' + str(tenant.get_json()))
コード例 #3
0
def main():
    """
    Main execution routine

    :return: None
    """
    # Create a tenant
    tenant = Tenant('Coke')

    # Create a Context and a BridgeDomain
    context = Context('VRF-1', tenant)
    context.set_allow_all()
    bd = BridgeDomain('BD-1', tenant)
    bd.add_context(context)

    # Create an App Profile and an EPG
    app = AppProfile('sap', tenant)
    epg = EPG('sapepg', app)

    # Attach the EPG to 2 interfaces using VLAN 5 as the encap
    if1 = Interface('eth', '1', '101', '1', '62')
    if2 = Interface('eth', '1', '101', '1', '63')
    vlan5_on_if1 = L2Interface('vlan5_on_if1', 'vlan', '5')
    vlan5_on_if2 = L2Interface('vlan5_on_if2', 'vlan', '5')
    vlan5_on_if1.attach(if1)
    vlan5_on_if2.attach(if2)
    epg.attach(vlan5_on_if1)
    epg.attach(vlan5_on_if2)

    # Dump the necessary configuration
    print('URL: '  + str(tenant.get_url()))
    print('JSON: ' + str(tenant.get_json()))

    send_to_apic(tenant)
コード例 #4
0
def main():
    """
    Main execution routine

    :return: None
    """
    creds = Credentials('apic')
    creds.add_argument('--tenant', help='The name of Tenant')
    creds.add_argument('--app', help='The name of ApplicationProfile')
    creds.add_argument('--bd', help='The name of BridgeDomain')
    creds.add_argument('--epg', help='The name of EPG')
    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)
    app = AppProfile(args.app, tenant)
    bd = BridgeDomain(args.bd, tenant)
    epg = EPG(args.epg, app)
    epg.add_bd(bd)

    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)
コード例 #5
0
def main():
    """
    Main execution routine
    """
    creds = Credentials('apic')
    args = creds.get()
    session = Session(args.url, args.login, args.password)
    session.login()

    tenant = Tenant('ATX16_l3Out')
    context = Context('vrf', tenant)
    outside_l3 = OutsideL3('out-1', tenant)
    outside_l3.add_context(context)
    phyif = Interface('eth', '1', '104', '1', '41')
    phyif.speed = '1G'
    l2if = L2Interface('eth 1/104/1/41', 'vlan', '1330')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    #l3if.set_l3if_type('l3-port')
    l3if.set_l3if_type('sub-interface')
    l3if.set_mtu('1500')
    l3if.set_addr('1.1.1.2/30')
    l3if.add_context(context)
    l3if.attach(l2if)
    rtr = OSPFRouter('rtr-1')
    rtr.set_router_id('23.23.23.23')
    rtr.set_node_id('101')
    ifpol = OSPFInterfacePolicy('myospf-pol', tenant)
    ifpol.set_nw_type('p2p')
    ospfif = OSPFInterface('ospfif-1', router=rtr, area_id='1')
    ospfif.set_area_type('nssa')
    ospfif.auth_key = 'password'
    ospfif.int_policy_name = ifpol.name
    ospfif.auth_keyid = '1'
    ospfif.auth_type = 'simple'
    tenant.attach(ospfif)
    ospfif.networks.append('55.5.5.0/24')
    ospfif.attach(l3if)
    contract1 = Contract('contract-1')
    outside_epg = OutsideEPG('outepg', outside_l3)
    outside_epg.provide(contract1)
    contract2 = Contract('contract-2')
    outside_epg.consume(contract2)
    outside_l3.attach(ospfif)

    print(tenant.get_json())
    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)
コード例 #6
0
def main():
    """
    Main execution routine
    """
    creds = Credentials('apic')
    args = creds.get()
    session = Session(args.url, args.login, args.password)
    session.login()

    tenant = Tenant('Cisco-Demo')
    context = Context('ctx1', tenant)
    outside_l3 = OutsideL3('out-1', tenant)
    outside_l3.add_context(context)
    phyif = Interface('eth', '1', '101', '1', '46')
    phyif.speed = '1G'
    l2if = L2Interface('eth 1/101/1/46', 'vlan', '1')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    l3if.set_l3if_type('l3-port')
    l3if.set_mtu('1500')
    l3if.set_addr('1.1.1.2/30')
    l3if.add_context(context)
    l3if.attach(l2if)
    rtr = OSPFRouter('rtr-1')
    rtr.set_router_id('23.23.23.23')
    rtr.set_node_id('101')
    ifpol = OSPFInterfacePolicy('myospf-pol', tenant)
    ifpol.set_nw_type('p2p')
    ospfif = OSPFInterface('ospfif-1', router=rtr, area_id='1')
    ospfif.set_area_type('nssa')
    ospfif.auth_key = 'password'
    ospfif.int_policy_name = ifpol.name
    ospfif.auth_keyid = '1'
    ospfif.auth_type = 'simple'
    tenant.attach(ospfif)
    ospfif.networks.append('55.5.5.0/24')
    ospfif.attach(l3if)
    contract1 = Contract('contract-1')
    outside_epg = OutsideEPG('outepg', outside_l3)
    outside_epg.provide(contract1)
    contract2 = Contract('contract-2')
    outside_epg.consume(contract2)
    outside_l3.attach(ospfif)

    print(tenant.get_json())
    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)
コード例 #7
0
def create_tenant(tenant_name):
    session = Session(config_data.get('url'), config_data.get('login'),
                      config_data.get('password'))
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')

    tenant = Tenant(tenant_name)

    # resp = tenant.push_to_apic(session)
    resp = session.push_to_acpi(tenant.get_url(), data=tenant.get_json())
    if not resp.ok:
        print('%% Error: Could not push configuration to APIC')
        print(resp.text)
コード例 #8
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)
コード例 #9
0
def main():
    """
    Main execution routine

    :return: None
    """
    creds = Credentials('apic')
    args = creds.get()
    session = Session(args.url, args.login, args.password)
    session.login()

    tenant = Tenant('cisco')
    context = Context('ctx1', tenant)
    outside_l3 = OutsideL3('out-1', tenant)
    phyif = Interface('eth', '1', '101', '1', '46')
    phyif.speed = '1G'
    l2if = L2Interface('eth 1/101/1/46', 'vlan', '1')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    l3if.set_l3if_type('l3-port')
    l3if.set_addr('1.1.1.2/30')
    l3if.add_context(context)
    l3if.attach(l2if)
    bgpif = BGPSession('test', peer_ip='1.1.1.1', node_id='101')
    bgpif.router_id = '172.1.1.1'
    bgpif.attach(l3if)
    bgpif.options = 'send-ext-com'
    bgpif.networks.append('0.0.0.0/0')
    contract1 = Contract('icmp')
    outside_epg = OutsideEPG('outepg', outside_l3)
    outside_epg.provide(contract1)
    outside_l3.add_context(context)
    outside_epg.consume(contract1)
    outside_l3.attach(bgpif)
    bgp_json = bgpif.get_json()

    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)
コード例 #10
0
def main():
    """
    Main execution routine

    :return: None
    """
    creds = Credentials('apic')
    args = creds.get()
    session = Session(args.url, args.login, args.password)
    session.login()

    tenant = Tenant('cisco')
    context = Context('ctx1', tenant)
    outside_l3 = OutsideL3('out-1', tenant)
    phyif = Interface('eth', '1', '101', '1', '46')
    phyif.speed = '1G'
    l2if = L2Interface('eth 1/101/1/46', 'vlan', '1')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    l3if.set_l3if_type('l3-port')
    l3if.set_addr('1.1.1.2/30')
    l3if.add_context(context)
    l3if.attach(l2if)
    bgpif = BGPSession('test', peer_ip='1.1.1.1', node_id='101')
    bgpif.router_id = '172.1.1.1'
    bgpif.attach(l3if)
    bgpif.options = 'send-ext-com'
    bgpif.networks.append('0.0.0.0/0')
    contract1 = Contract('icmp')
    outside_epg = OutsideEPG('outepg', outside_l3)
    outside_epg.provide(contract1)
    outside_l3.add_context(context)
    outside_epg.consume(contract1)
    outside_l3.attach(bgpif)
    bgp_json = bgpif.get_json()

    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)
コード例 #11
0
from acitoolkit.acitoolkit import Session, Credentials, Tenant

creds = Credentials('apic', 'Opis co skrypt robi.')
args = creds.get()

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

resp = session.login()
if not resp.ok:
    print 'Could not login to APIC'

tenant = Tenant('mytenat')

resp = session.push_to_apic(tenant.get_url(), tenant.get_json())
if not resp.ok:
    print 'Could not push configuration to APIC'
    print resp.text

tenants = Tenant.get(session)
for tenant in tenants:
    print tenant.name

session.close()
コード例 #12
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()))
コード例 #13
0
def setup_multisite_test(printonly=False, delete=False):
    # Create the Tenant
    tenant1 = Tenant('multisite')

    # Create the Application Profile
    app = AppProfile('my-demo-app', tenant1)

    # Create the EPGs
    web_epg = EPG('web-frontend', app)
    db_epg = EPG('database-backend', app)

    # Create a Context and BridgeDomain
    # Place both EPGs in the Context and in the same BD
    context = Context('VRF-1', tenant1)
    bd = BridgeDomain('BD-1', tenant1)
    bd.add_context(context)
    web_epg.add_bd(bd)
    db_epg.add_bd(bd)

    # Define a contract with a single entry
    contract = Contract('multisite_mysqlcontract', tenant1)
    entry1 = FilterEntry('entry1',
                         applyToFrag='no',
                         arpOpc='unspecified',
                         dFromPort='3306',
                         dToPort='3306',
                         etherT='ip',
                         prot='tcp',
                         sFromPort='1',
                         sToPort='65535',
                         tcpRules='unspecified',
                         parent=contract)

    # Provide the contract from 1 EPG and consume from the other
    db_epg.provide(contract)
    web_epg.consume(contract)

    context = Context('ctx0', tenant1)
    #contract = Contract('contract', tenant)
    phyif = Interface('eth', '1', '102', '1', '25')
    l2if = L2Interface('eth 1/102/1/25', 'vlan', '500')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    l3if.set_l3if_type('ext-svi')
    l3if.set_addr('20.0.0.1/16')
    l3if.add_context(context)
    l3if.attach(l2if)

    #l3if.networks.append('1.1.1.1/32')
    #outside.provide(contract)
    l3if.attach(l2if)
    rtr = OSPFRouter('rtr-1')
    rtr.set_router_id('101.101.101.101')
    rtr.set_node_id('102')
    # net1 = OutsideNetwork('1.1.1.1/32')
    # net1.network = '1.1.1.1/32'
    # net1.provide(contract)
    ospfif = OSPFInterface('ospfif-1', router=rtr, area_id='0.0.0.1')
    ospfif.attach(l3if)
    # ospfif.networks.append(net1)
    outside = OutsideEPG('multisite-l3out', tenant1)
    outside.attach(ospfif)
    #outside.add_context(context)

    # Create the Tenant
    tenant2 = Tenant('multisite')

    # Create the Application Profile
    app = AppProfile('my-demo-app', tenant2)

    # Create the EPGs
    web_epg = EPG('web-frontend', app)

    # Create a Context and BridgeDomain
    # Place both EPGs in the Context and in the same BD
    context = Context('VRF-1', tenant2)
    bd = BridgeDomain('BD-1', tenant2)
    bd.add_context(context)
    web_epg.add_bd(bd)

    context = Context('ctx0', tenant2)
    #contract = Contract('contract', tenant)
    phyif = Interface('eth', '1', '102', '1', '25')
    l2if = L2Interface('eth 1/102/1/25', 'vlan', '500')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    l3if.set_l3if_type('ext-svi')
    l3if.set_addr('20.0.0.2/16')
    l3if.add_context(context)
    l3if.attach(l2if)
    #outside.provide(contract)
    l3if.attach(l2if)
    rtr = OSPFRouter('rtr-1')
    rtr.set_router_id('102.102.102.102')
    rtr.set_node_id('102')
    ospfif = OSPFInterface('ospfif-1', router=rtr, area_id='0.0.0.1')
    ospfif.attach(l3if)
    #ospfif.networks.append('1.1.1.1/32')
    #ospfif.networks.append('1.1.1.2/32')
    outside = OutsideEPG('multisite-l3out', tenant2)
    outside.attach(ospfif)

    if not printonly:
        # Login to APIC and push the config
        session = Session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
        session.login()
        # Cleanup (uncomment the next line to delete the config)
        if delete:
            print 'Deleting...'
            tenant1.mark_as_deleted()
        resp = tenant1.push_to_apic(session)
        if resp.ok:
            # Print what was sent
            print('Pushed the following JSON to the APIC', resp.text)
        else:
            print resp, resp.text
    print('URL: '  + str(tenant1.get_url()))
    print('JSON:')
    print json.dumps(tenant1.get_json(), indent=4, separators=(',',':'))


    if not printonly:
        # Login to APIC and push the config
        session = Session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
        session.login()
        # Cleanup (uncomment the next line to delete the config)
        if delete:
            tenant2.mark_as_deleted()
        resp = tenant2.push_to_apic(session)
        if resp.ok:
            # Print what was sent
            print('Pushed the following JSON to the APIC', resp.text)
        else:
            print resp, resp.text
    print('URL: '  + str(tenant2.get_url()))
    print('JSON:')
    print json.dumps(tenant2.get_json(), indent=4, separators=(',',':'))
def main():

    description = ('Create 2 EPGs within the same Context and have'
                   '1 EPG provide a contract to the other EPG.')
    creds = Credentials('apic', description)
    args = creds.get()
    session = Session(args.url, args.login, args.password)
    session.login()
    for line in data:
            line = line.strip("\n")
            tnt = line.split(",")[0]
            appro = line.split(",")[1]
            epg1 = line.split(",")[2]
            epg2 = line.split(",")[3]
            contractn = line.split(",")[4]
            bd1 = line.split(",")[5]
            vrf1 = line.split(",")[6]
    # Create the Tenant
            tenant = Tenant(tnt)

    # Create the Application Profile
            app = AppProfile(appro, tenant)

    # Create the EPGs
            epg_obj1 = EPG(epg1, app)
            epg_obj2 = EPG(epg2, app)
            epg_obj1.set_intra_epg_isolation(False)
            epg_obj2.set_intra_epg_isolation(True)

    # Create a Context and BridgeDomain
    # Place both EPGs in the Context and in the same BD
            context = Context(vrf1, tenant)
            bd = BridgeDomain(bd1, tenant)
            bd.add_context(context)
            epg_obj1.add_bd(bd)
            epg_obj2.add_bd(bd)

    # Define a contract with a single entry
            contract = Contract(contractn, tenant)
            entry1 = FilterEntry('entry1',
                                applyToFrag='no',
                                arpOpc='unspecified',
                                dFromPort='3306',
                                dToPort='3306',
                                etherT='ip',
                                prot='tcp',
                                sFromPort='1',
                                sToPort='65535',
                                tcpRules='unspecified',
                                parent=contract)

    # Provide the contract from 1 EPG and consume from the other
            epg_obj2.provide(contract)
            epg_obj1.consume(contract)

    # Login to APIC and push the config

    # Cleanup (uncomment the next line to delete the config)
    # tenant.mark_as_deleted()
            resp = tenant.push_to_apic(session)

            if resp.ok:
        # Print what was sent
                print('Pushed the following JSON to the APIC')
                print('URL: ' + str(tenant.get_url()))
                print('JSON: ' + str(tenant.get_json()))
コード例 #15
0
Phy_links=(Link)
Phy_pwrs=(Powersupply)

    # Get and print all of the items from the APIC
items = phy_class.get(session)
for item in items:
    print item.info()
    
links=Phy_links.get(session)

for link in links:
    print link.info() 
    
pwrs=Phy_pwrs.get(session)
for pwr in pwrs:
    print pwr.info()
        


for node in Node.get(session):
    print node.info()
    
tenant = Tenant('Alex_Tenant')    
    
res=session.get(tenant.get_url())
print res.text



if __name__ == '__main__':
    pass
コード例 #16
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()))