コード例 #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)
コード例 #2
0
 def create_tenant_for_scalabilityTest(self, session,
                                       numberOfTenants_toBecreated,
                                       domain_toBe_attached):
     tenant_Prefix = "FVT_TenantScale_Test"
     app_Profile_name = "FVT_ApPScale_Test"
     epg_name = "FVT_epgScale_Test"
     domainflg = False
     for tenant_no in range(0, int(numberOfTenants_toBecreated)):
         tenant_toBe_created = tenant_Prefix + str(tenant_no)
         appP_toBe_created = app_Profile_name + str(tenant_no)
         epg_toBe_created = epg_name + str(tenant_no)
         tenant = aci.Tenant(tenant_toBe_created)
         app = aci.AppProfile(appP_toBe_created, tenant)
         epg = EPG(epg_toBe_created, app)
         domains = aci.VmmDomain.get(session)
         for domain in domains:
             if str(domain) == domain_toBe_attached:
                 domainflg = True
                 epg.attach(domain)
         if domainflg:
             resp = session.push_to_apic(tenant.get_url(),
                                         tenant.get_json())
             time.sleep(1)
             if resp.ok:
                 print("*** {} Tenant Created".format(str(tenant)))
         else:
             print('%% Error: Could not push configuration to APIC')
コード例 #3
0
    def test_preexisting_endpoints_consume_imported_contract(self):
        self.setup_export_contract()
        self.consume_exported_contract()

        session2 = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        new_epg_name = 'another-epg'
        web_epg = EPG(new_epg_name, app)

        # Create the Endpoint
        mac = '00:77:55:44:33:22'
        ip = '8.3.2.1'
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        resp = tenant.push_to_apic(session2)
        self.assertTrue(resp.ok)

        self.consume_exported_contract(epg_name=new_epg_name)

        tenants = Tenant.get_deep(session2, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, new_epg_name)
        self.assertIsNotNone(epg)
        multisite_ep = epg.get_child(Endpoint, mac)
        self.assertIsNotNone(multisite_ep)

        session1 = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
        self._assert_l3extsubnet_exists(session1,
                                        tenant_name='multisite',
                                        mac=mac,
                                        ip=ip)

        self.unconsume_exported_contract(new_epg_name)
        time.sleep(2)

        self._assert_l3extsubnet_does_not_exist(session1,
                                                tenant_name='multisite',
                                                mac=mac,
                                                ip=ip)
        web_epg.mark_as_deleted()
        tenant.push_to_apic(session2)

        time.sleep(1)

        self.teardown_export_contract()
コード例 #4
0
    def test_preexisting_endpoints_consume_imported_contract(self):
        self.setup_export_contract()
        self.consume_exported_contract()

        session2 = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        new_epg_name = 'another-epg'
        web_epg = EPG(new_epg_name, app)

        # Create the Endpoint
        mac = '00:77:55:44:33:22'
        ip = '8.3.2.1'
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        resp = tenant.push_to_apic(session2)
        self.assertTrue(resp.ok)

        self.consume_exported_contract(epg_name=new_epg_name)

        tenants = Tenant.get_deep(session2, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, new_epg_name)
        self.assertIsNotNone(epg)
        multisite_ep = epg.get_child(Endpoint, mac)
        self.assertIsNotNone(multisite_ep)

        session1 = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
        self._assert_l3extsubnet_exists(session1,
                                        tenant_name='multisite',
                                        mac=mac,
                                        ip=ip)

        self.unconsume_exported_contract(new_epg_name)
        time.sleep(2)

        self._assert_l3extsubnet_does_not_exist(session1,
                                                tenant_name='multisite',
                                                mac=mac,
                                                ip=ip)
        web_epg.mark_as_deleted()
        tenant.push_to_apic(session2)

        time.sleep(1)

        self.teardown_export_contract()
コード例 #5
0
def send_to_apic():
    """
    Login to APIC and push the config
    :param tenant: Tenant class instance
    :return: request response object
    """
    description = 'Basic Connectivity Example'
    creds = Credentials('apic', description)
    args = creds.get()
    # Login to APIC
    session = Session(args.url, args.login, args.password, False)
    session.login()
    tenants = aci.Tenant.get(session)
    user_tenant = "OneView-APIC-Tenant-1"
    user_appProfile = "OneView-APIC-AppProfile-1"
    for tenant in tenants:
        if str(tenant) == user_tenant.strip():
            apps = aci.AppProfile.get(session, tenant)
            for app in apps:
                if str(app) == user_appProfile:
                    epg1 = "EPG"
                    for number in range(0, 10):
                        epgg = epg1 + str(number)
                        epg = EPG(epgg, app)
                        domains = aci.VmmDomain.get(session)
                        for domain in domains:
                            if str(domain) == "OneView-APIC-vSwitch-Bay1":
                                epg.attach(domain)
        resp = tenant.push_to_apic(session)
コード例 #6
0
    def add_consuming_static_endpoint(self,
                                      mac,
                                      ip,
                                      site1=False,
                                      epg_name='web-frontend'):
        if site1:
            session = self._login_session(SITE1_URL, SITE1_LOGIN,
                                          SITE1_PASSWORD)
        else:
            session = self._login_session(SITE2_URL, SITE2_LOGIN,
                                          SITE2_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        web_epg = EPG(epg_name, app)

        # Create the Endpoint
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        resp = tenant.push_to_apic(session)
        self.assertTrue(resp.ok)

        tenants = Tenant.get_deep(session, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, epg_name)
        self.assertIsNotNone(epg)
        ep = epg.get_child(Endpoint, mac)
        self.assertIsNotNone(ep)

        if site1:
            session = self._login_session(SITE2_URL, SITE2_LOGIN,
                                          SITE2_PASSWORD)
        else:
            session = self._login_session(SITE1_URL, SITE1_LOGIN,
                                          SITE1_PASSWORD)
        self._assert_l3extsubnet_exists(session,
                                        tenant_name='multisite',
                                        mac=mac,
                                        ip=ip)
コード例 #7
0
    def add_consuming_static_endpoint(self, mac, ip, site1=False, epg_name='web-frontend'):
        if site1:
            session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
        else:
            session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        web_epg = EPG(epg_name, app)

        # Create the Endpoint
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        resp = tenant.push_to_apic(session)
        self.assertTrue(resp.ok)

        tenants = Tenant.get_deep(session, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, epg_name)
        self.assertIsNotNone(epg)
        ep = epg.get_child(Endpoint, mac)
        self.assertIsNotNone(ep)

        if site1:
            session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
        else:
            session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
        self._assert_l3extsubnet_exists(session,
                                        tenant_name='multisite',
                                        mac=mac,
                                        ip=ip)
コード例 #8
0
    def add_providing_static_endpoint(self, mac, ip):
        session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        web_epg = EPG('database-backend', app)

        # Create the Endpoint
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        resp = tenant.push_to_apic(session)
        if not resp.ok:
            self.assertTrue(resp.ok)
            print resp, resp.text

        time.sleep(1)
        # Verify that the Endpoint was pushed successfully
        tenants = Tenant.get_deep(session, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, 'database-backend')
        self.assertIsNotNone(epg)
        ep = epg.get_child(Endpoint, mac)
        self.assertIsNotNone(ep)

        # Verify that the entry was pushed to the other site
        session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
        self._assert_l3extsubnet_exists(session,
                                        tenant_name='multisite',
                                        mac=mac,
                                        ip=ip)
コード例 #9
0
    def add_providing_static_endpoint(self, mac, ip):
        session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        web_epg = EPG('database-backend', app)

        # Create the Endpoint
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        resp = tenant.push_to_apic(session)
        if not resp.ok:
            self.assertTrue(resp.ok)
            print resp, resp.text

        time.sleep(1)
        # Verify that the Endpoint was pushed successfully
        tenants = Tenant.get_deep(session, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, 'database-backend')
        self.assertIsNotNone(epg)
        ep = epg.get_child(Endpoint, mac)
        self.assertIsNotNone(ep)

        # Verify that the entry was pushed to the other site
        session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
        self._assert_l3extsubnet_exists(session,
                                        tenant_name='multisite',
                                        mac=mac,
                                        ip=ip)
コード例 #10
0
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())
コード例 #11
0
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())
コード例 #12
0
    def remove_providing_static_endpoint(self, mac, ip):
        session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        web_epg = EPG('database-backend', app)

        # Create the Endpoint
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        # Mark the Endpoint as deleted
        ep.mark_as_deleted()

        resp = tenant.push_to_apic(session)
        self.assertTrue(resp.ok)

        # Verify that the Endpoint has been removed
        time.sleep(1)
        tenants = Tenant.get_deep(session, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, 'web-frontend')
        self.assertIsNotNone(epg)
        ep = epg.get_child(Endpoint, mac)
        self.assertIsNone(ep)
コード例 #13
0
    def remove_providing_static_endpoint(self, mac, ip):
        session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)

        tenant = Tenant('multisite')
        app = AppProfile('my-demo-app', tenant)
        web_epg = EPG('database-backend', app)

        # Create the Endpoint
        ep = Endpoint(mac, web_epg)
        ep.mac = mac
        ep.ip = ip

        intf = Interface('eth', '1', '101', '1', '38')
        # Create a VLAN interface and attach to the physical interface
        vlan_intf = L2Interface('vlan-5', 'vlan', '5')
        vlan_intf.attach(intf)
        # Attach the EPG to the VLAN interface
        web_epg.attach(vlan_intf)
        # Assign Endpoint to the L2Interface
        ep.attach(vlan_intf)

        # Mark the Endpoint as deleted
        ep.mark_as_deleted()

        resp = tenant.push_to_apic(session)
        self.assertTrue(resp.ok)

        # Verify that the Endpoint has been removed
        time.sleep(1)
        tenants = Tenant.get_deep(session, names=['multisite'])
        multisite_tenant = tenants[0]
        app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
        self.assertIsNotNone(app)
        epg = app.get_child(EPG, 'web-frontend')
        self.assertIsNotNone(epg)
        ep = epg.get_child(Endpoint, mac)
        self.assertIsNone(ep)
コード例 #14
0
def main():

    description = ('Create 3 EPGs within the same Bridge Domain and have'
                   '2 EPGs provide a contract to the other EPG.')
    creds = Credentials('apic', description)
    args = creds.get()

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

    if log.ok:
        print('Login to APIC successful !!!')

    if not log.ok:
        print('Error: Could not login to APIC')
        print(log.status_code)

    # Create the Tenant
    name_tenant = input('Enter Tenant name: ')
    tenant = Tenant(name_tenant)
    tenant_resp = tenant.push_to_apic(session)

    if tenant_resp.ok:
        print('Tenant created successfully !!!')

    if not tenant_resp.ok:
        print('Error: Could not create Tenant')
        print(tenant_resp.status_code)

    # Gets vmm domain from APIC
    vmm = VmmDomain.get_by_name(session, 'vCenter-ACI')
    vmm_resp = tenant.push_to_apic(session)

    if vmm_resp.ok:
        print('VmmDomain: vCenter-ACI, opened successfully !!!')

    if not vmm_resp.ok:
        print('Error: Could not open VmmDomain: vCenter-ACI')
        print(vmm_resp.status_code)

    # Create the Application Profile
    name_ap = input('Enter Application Profile name: ')
    app = AppProfile(name_ap, tenant)
    app_resp = tenant.push_to_apic(session)

    if app_resp.ok:
        print('Application Profile created successfully !!!')

    if not app_resp.ok:
        print('Error: Could not create Application Profile')
        print(app_resp.status_code)

    # Create the WEB EPG
    web_epg = EPG('WEB', app)
    web_resp = tenant.push_to_apic(session)

    if web_resp.ok:
        print('WEB epg created successfully !!!')

    if not web_resp.ok:
        print('Error: Could not create WEB epg')
        print(web_resp.status_code)

    # Create the DATA EPG
    db_epg = EPG('DATA', app)
    db_resp = tenant.push_to_apic(session)

    if db_resp.ok:
        print('DATA epg created successfully !!!')

    if not db_resp.ok:
        print('Error: Could not create DATA epg')
        print(db_epg.status_code)

    # Create the APP EPG
    app_epg = EPG('APP', app)
    app_resp = tenant.push_to_apic(session)

    if app_resp.ok:
        print('APP epg created successfully !!!')

    if not app_resp.ok:
        print('Error: Could not create APP epg')
        print(app_epg.status_code)

    # Associating EPGs to Vmm Domain
    web_epg.attach(vmm)
    db_epg.attach(vmm)
    app_epg.attach(vmm)

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

    # Define web-to app contract
    contract1 = Contract('web-to-app', tenant)
    entry1 = FilterEntry('entry1',
                         applyToFrag='no',
                         arpOpc='unspecified',
                         dFromPort='443',
                         dToPort='443',
                         etherT='ip',
                         prot='tcp',
                         sFromPort='1',
                         sToPort='65535',
                         tcpRules='unspecified',
                         parent=contract1)

    # Define app-to-data contract
    contract2 = Contract('app-to-data', tenant)

    entry2 = FilterEntry('entry2',
                         applyToFrag='no',
                         arpOpc='unspecified',
                         dFromPort='1433',
                         dToPort='1433',
                         etherT='ip',
                         prot='tcp',
                         sFromPort='1',
                         sToPort='65535',
                         tcpRules='unspecified',
                         parent=contract2)

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

    ########### ClEANUP (uncomment the next line to delete the tenant)
    #tenant.mark_as_deleted()
    ####################################

    #Push all the config to apic
    resp = tenant.push_to_apic(session)

    if resp.ok:
        print('All the configuration was pushed to APIC !!!')

    if not resp.ok:
        print('Error: Could not push configuration to APIC')
        print(resp.status_code)