Exemple #1
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)
Exemple #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('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)
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 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)
Exemple #7
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)
def main():
    """
    Main execution routine

    :return: None
    """
    # Create the physical interface objects
    intf1 = Interface('eth', '1', '101', '1', '38')
    intf2 = Interface('eth', '1', '101', '1', '39')
    intf3 = Interface('eth', '1', '102', '1', '38')
    intf4 = Interface('eth', '1', '102', '1', '39')

    # Create a port channel and add physical interfaces
    pc = PortChannel('pc1')
    pc.attach(intf1)
    pc.attach(intf2)
    pc.attach(intf3)
    pc.attach(intf4)
    # pc.mark_as_deleted()

    # Create a VLAN interface on the port channel
    # This is the L2 interface representing a single VLAN encap
    # on this particular interface.
    vlan5_on_pc = L2Interface('vlan5_on_pc', 'vlan', '5')
    vlan5_on_pc.attach(pc)

    # Create a tenant, app profile, and epg
    tenant = Tenant('acitoolkitdemo')
    app = AppProfile('app', tenant)
    epg = EPG('epg', app)

    # Connect EPG to the VLAN interface
    # Remember, this VLAN interface is on the port channel we created
    # so the EPG will be attached to the port channel on VLAN 5
    epg.attach(vlan5_on_pc)

    # Print the resulting JSON
    print(pc.get_json())
    print(tenant.get_json())