Пример #1
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)
Пример #2
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)
def create_interface(tenant, session, epgs):
    ''' The epgs are in the form of a dictionary with provide and consume.  
        There can be only one of each.
    '''

    context = Context('{}_VRF'.format(tenant), tenant)
    outside_l3 = OutsideL3('Campus_Connection', tenant)
    outside_l3.add_context(context)
    phyif = Interface('eth', '1', '201', '1', '6')
    phyif.speed = '1G'
    l2if = L2Interface('eth 201/1/6', 'vlan', '40')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    l3if.set_l3if_type('l3-port')
    # l3if.set_mtu('1500')
    l3if.set_addr('192.168.255.2/24')
    l3if.add_context(context)
    l3if.attach(l2if)
    rtr = OSPFRouter('rtr-2')
    rtr.set_router_id('22.22.22.22')
    rtr.set_node_id('201')
    ifpol = OSPFInterfacePolicy('1G_OSPF', tenant)
    #ifpol.set_nw_type('p2p')
    ospfif = OSPFInterface('Campus_IF', router=rtr, area_id='42')
    ospfif.auth_key = ''
    ospfif.int_policy_name = ifpol.name
    ospfif.auth_keyid = '1'
    ospfif.auth_type = 'simple'
    tenant.attach(ospfif)
    ospfif.networks.append('0.0.0.0/0')
    ospfif.attach(l3if)
    contract1 = Contract(epgs['provide'])
    outside_epg = OutsideEPG('Campus_Gateway-EPG', outside_l3)
    outside_epg.provide(contract1)
    contract2 = Contract(epgs['consume'])
    outside_epg.consume(contract2)
    outside_l3.attach(ospfif)

    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_interface(tenant, session, epgs):
    ''' The epgs are in the form of a dictionary with provide and consume.  
        There can be only one of each.
    '''

    context = Context('{}_VRF'.format(tenant), tenant)
    outside_l3 = OutsideL3('Campus_Connection', tenant)
    outside_l3.add_context(context)
    phyif = Interface('eth', '1', '201', '1', '6')
    phyif.speed = '1G'
    l2if = L2Interface('eth 201/1/6', 'vlan', '40')
    l2if.attach(phyif)
    l3if = L3Interface('l3if')
    l3if.set_l3if_type('l3-port')
    # l3if.set_mtu('1500')
    l3if.set_addr('192.168.255.2/24')
    l3if.add_context(context)
    l3if.attach(l2if)
    rtr = OSPFRouter('rtr-2')
    rtr.set_router_id('22.22.22.22')
    rtr.set_node_id('201')
    ifpol = OSPFInterfacePolicy('1G_OSPF', tenant)
    #ifpol.set_nw_type('p2p')
    ospfif = OSPFInterface('Campus_IF', router=rtr, area_id='42')
    ospfif.auth_key = ''
    ospfif.int_policy_name = ifpol.name
    ospfif.auth_keyid = '1'
    ospfif.auth_type = 'simple'
    tenant.attach(ospfif)
    ospfif.networks.append('0.0.0.0/0')
    ospfif.attach(l3if)
    contract1 = Contract(epgs['provide'])
    outside_epg = OutsideEPG('Campus_Gateway-EPG', outside_l3)
    outside_epg.provide(contract1)
    contract2 = Contract(epgs['consume'])
    outside_epg.consume(contract2)
    outside_l3.attach(ospfif)

    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 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=(',',':'))