def consume_exported_contract(self, epg_name='web-frontend'): session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD) # Create the Tenant tenant = Tenant('multisite') # Create the Application Profile app = AppProfile('my-demo-app', tenant) # Create the EPGs web_epg = EPG(epg_name, app) contract = Contract('Site1:multisite_mysqlcontract', tenant) web_epg.consume(contract) tenant.push_to_apic(session) # Verify that the EPG is indeed consuming the contract tenants = Tenant.get_deep( session, names=['multisite'], limit_to=['fvTenant', 'fvAp', 'fvAEPg', 'fvRsCons', 'vzBrCP']) self.assertTrue(len(tenants) > 0) 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) contract = multisite_tenant.get_child(Contract, 'Site1:multisite_mysqlcontract') self.assertIsNotNone(contract) self.assertTrue(epg.does_consume(contract))
def get_tree(): """ Will build an object tree with attributes in each object :return: """ tenant = Tenant('tenant') tenant.dn = '/tn-tenant' app1 = AppProfile('app1', tenant) app1.dn = app1._parent.dn + '/app-app1' app2 = AppProfile('app2', tenant) app2.dn = app2._parent.dn + '/app-app2' epg11 = EPG('epg11', app1) epg11.dn = epg11._parent.dn + '/epg-epg11' epg12 = EPG('epg12', app1) epg12.dn = epg12._parent.dn + '/epg-epg12' epg21 = EPG('epg21', app2) epg21.dn = epg21._parent.dn + '/epg-epg21' epg22 = EPG('epg22', app2) epg22.dn = epg22._parent.dn + '/epg-epg22' bd1 = BridgeDomain('bd1', tenant) bd1.dn = bd1._parent.dn + '/bd-bd1' bd2 = BridgeDomain('bd2', tenant) bd2.dn = bd2._parent.dn + '/bd-bd2' epg11.add_bd(bd1) epg12.add_bd(bd2) epg21.add_bd(bd1) epg22.add_bd(bd2) context = Context('ctx', tenant) context.dn = context._parent.dn + '/ctx-ctx' bd1.add_context(context) bd2.add_context(context) contract1 = Contract('contract-1', tenant) contract1.dn = contract1._parent.dn + '/con-contract1' entry1 = FilterEntry('entry1', applyToFrag='no', arpOpc='unspecified', dFromPort='80', dToPort='80', etherT='ip', prot='tcp', sFromPort='1', sToPort='65535', tcpRules='unspecified', parent=contract1) subjects = contract1.get_children(ContractSubject) for subject in subjects: subject.dn = subject._parent.dn + '/subj-' + subject.name filters = tenant.get_children(Filter) for atk_filter in filters: atk_filter.dn = atk_filter._parent.dn + '/flt-' + atk_filter.name entry1.dn = entry1._parent.dn + '/flte-entry1' epg11.provide(contract1) epg11.consume(contract1) epg12.consume(contract1) epg11.value1 = 'value2' bd1.value2 = 'value1' return tenant
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()))
def consume_exported_contract(self, epg_name='web-frontend'): session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD) # Create the Tenant tenant = Tenant('multisite') # Create the Application Profile app = AppProfile('my-demo-app', tenant) # Create the EPGs web_epg = EPG(epg_name, app) contract = Contract('Site1:multisite_mysqlcontract', tenant) web_epg.consume(contract) tenant.push_to_apic(session) # Verify that the EPG is indeed consuming the contract tenants = Tenant.get_deep(session, names=['multisite'], limit_to=['fvTenant', 'fvAp', 'fvAEPg', 'fvRsCons', 'vzBrCP']) self.assertTrue(len(tenants) > 0) 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) contract = multisite_tenant.get_child(Contract, 'Site1:multisite_mysqlcontract') self.assertIsNotNone(contract) self.assertTrue(epg.does_consume(contract))
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)
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)
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()
def main(): """ Create 2 Tenants with a single EPG in each. Between the 2 tenants, the EPGs communicate through an exported contract. """ description = ('Create 2 Tenants with a single EPG in each. Between the 2 tenants,' 'the EPGs communicate through an exported contract.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 first Tenant tenant1 = Tenant('common') app1 = AppProfile('app-1', tenant1) web_epg = EPG('web-frontend', app1) # Create the second Tenant tenant2 = Tenant('aci-2') app2 = AppProfile('app-2', tenant2) db_epg = EPG('database-backend', app2) # Define a contract with a single entry contract = Contract('mysql-contract', tenant2) 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 db_epg.provide(contract) # Import the contract into the other tenant imported_contract = ContractInterface('mysql-imported-contract', tenant1) imported_contract.import_contract(contract) # Consume the contract in the second tenant web_epg.consume_cif(imported_contract) # Login to APIC and push the config session = Session(args.url, args.login, args.password) session.login() # Cleanup (uncomment the next 2 lines to delete the config) # tenant1.mark_as_deleted() # tenant2.mark_as_deleted() for tenant in [tenant2, tenant1]: 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()))
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)
def create_application_profile(tenant_name, ap_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) ap = AppProfile(ap_name, tenant) resp = tenant.push_to_apic(session) if not resp.ok: print('%% Error: Could not push configuration to APIC') print(resp.text)
def del_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) tenant.mark_as_deleted() resp = tenant.push_to_apic(session) if not resp.ok: print('%% Error: Could not push configuration to APIC') print(resp.text)
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)
def del_epg(tenant_name, ap_name, epg_name, bd_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) ap = AppProfile(ap_name, tenant) bd = BridgeDomain(bd_name, tenant) epg = EPG(epg_name, ap) epg.mark_as_deleted() resp = tenant.push_to_apic(session) if not resp.ok: print('%% Error: Could not push configuration to APIC') print(resp.text)
def getOldTenant(): tenants_list = [] tenants = Tenant.get(session) for tenant in tenants: if tenant.name != 'mgmt' and tenant.name != 'infra' and tenant.name != 'common': tenants_list.append((tenant)) print('\nTenants on the system') print('=====================') for a in range(len(tenants_list)): print str(a) + ': ' + tenants_list[a].name tenant_in = 99999 while tenant_in > 99998: error = False input = raw_input( '\nPlease enter the Tenant # where the application is you want to duplicate: ' ) try: tenant_in = int(input) except: error = True if tenant_in > len(tenants_list) - 1: error = True if error: tenant_in = 99999 print('Please select a Tenant number from the list.') return tenants_list[tenant_in]
def unconsume_exported_contract(self, epg_name): session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD) # Create the Tenant tenant = Tenant('multisite') # Create the Application Profile app = AppProfile('my-demo-app', tenant) # Create the EPGs web_epg = EPG(epg_name, app) contract = Contract('Site1:multisite_mysqlcontract', tenant) web_epg.consume(contract) web_epg.dont_consume(contract) resp = tenant.push_to_apic(session) if not resp.ok: print resp, resp.text self.assertTrue(resp.ok)
def getOldTenant(): tenants_list = [] tenants = Tenant.get(session) for tenant in tenants: if tenant.name != 'mgmt' and tenant.name != 'infra' and tenant.name != 'common': tenants_list.append((tenant)) print ('\nTenants on the system') print ('=====================') for a in range(len(tenants_list)): print str(a) + ': ' + tenants_list[a].name tenant_in = 99999 while tenant_in > 99998: error = False input = raw_input('\nPlease enter the Tenant # where the application is you want to duplicate: ') try: tenant_in = int(input) except: error = True if tenant_in > len(tenants_list)-1: error = True if error: tenant_in = 99999 print ('Please select a Tenant number from the list.') return tenants_list[tenant_in]
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 delete_tenant_for_scalabilityTest(self, session): tenants = Tenant.get(session) for tenant in tenants: if re.match("FVT_TenantScale_Test\d+", str(tenant)): tenant.mark_as_deleted() resp = session.push_to_apic(tenant.get_url(), tenant.get_json()) if resp.ok: print('***{} Tenant Deleted'.format(str(tenant)))
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)
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 dettach_epg_provide_contract(tenant_name, ap_name, epg_name, provided_contract="", consumed_contract=""): 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) ap = AppProfile(ap_name, tenant) epg = EPG(epg_name, ap) if provided_contract: provided_contract = Contract(provided_contract, tenant) epg.dont_provide(provided_contract) if consumed_contract: consumed_contract = Contract(consumed_contract, tenant) epg.dont_consume(consumed_contract) resp = tenant.push_to_apic(session) 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())
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)
def main(): creds = Credentials('apic') args = creds.get() session = Session(args.url, args.login, args.password) session.login() tenant = 'A_SCRIPT_MADE_ME' theTenant = Tenant(tenant) create_interface(theTenant, session, { 'provide': 'Outbound_Server', 'consume': 'Web' }) print("Created a Layer 3 External gateway in tenant {}.".format(theTenant)) print("Everything seems to have worked if you are seeing this.")
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 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
def main(): with open(CONFFILE, 'r') as r: conf = json.loads(r.read()) #login to apic session = Session(conf['url'], conf['login'], conf['password']) resp = session.login() if not resp.ok: print('%% Could not login to APIC') return sys.exit(0) tenants = Tenant.get(session) for tenant in tenants: print(tenant.name)
def unexport_contract(self, url): time.sleep(5) driver = self.__class__.driver # Switch to the site 1 tool driver.get(url) # Click on Site Contracts driver.find_element_by_link_text('Site Contracts').click() self.click_on_contract('multisite_mysqlcontract') # Select the pulldown driver.find_element_by_link_text('With selected').click() driver.find_element_by_link_text('Change Export Settings').click() assert 'Export Contracts' in driver.title # Check that the Sites checkbox is checked checkbox = driver.find_element_by_id('sites-0') self.assertTrue(checkbox.is_selected()) # Select the site checkbox.click() # Export the contract driver.find_element_by_id('submit').click() time.sleep(1) # Verify that the unexport from the other APIC was successful session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD) tenants = Tenant.get_deep(session, names=['multisite'], limit_to=['fvTenant', 'vzBrCP']) self.assertTrue(len(tenants) > 0) multisite_tenant = tenants[0] self.assertIsNone( multisite_tenant.get_child(Contract, 'Site1:multisite_mysqlcontract')) # Verify that the tag is removed in the remote site mtag = MultisiteTag('multisite_mysqlcontract', 'imported', 'Site1') self._verify_tag(session, 'multisite', str(mtag), exists=False) # Verify that the tag is removed locally session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD) mtag = MultisiteTag('multisite_mysqlcontract', 'exported', 'Site2') self._verify_tag(session, 'multisite', str(mtag), exists=False)
def main(): # Setup or credentials and session description = ('Common contracts and filters') creds = Credentials('apic', description) args = creds.get() # Login to APIC session = Session(args.url, args.login, args.password) session.login() # This creates the tenant object theTenant = Tenant(tenant) create_all_contracts(theTenant, session) print("Created common contracts and filters in the {} tenant.".format( theTenant)) print("Everything seems to have worked if you are seeing this.")
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 unexport_contract(self, url): time.sleep(5) driver = self.__class__.driver # Switch to the site 1 tool driver.get(url) # Click on Site Contracts driver.find_element_by_link_text('Site Contracts').click() self.click_on_contract('multisite_mysqlcontract') # Select the pulldown driver.find_element_by_link_text('With selected').click() driver.find_element_by_link_text('Change Export Settings').click() assert 'Export Contracts' in driver.title # Check that the Sites checkbox is checked checkbox = driver.find_element_by_id('sites-0') self.assertTrue(checkbox.is_selected()) # Select the site checkbox.click() # Export the contract driver.find_element_by_id('submit').click() time.sleep(1) # Verify that the unexport from the other APIC was successful session = self._login_session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD) tenants = Tenant.get_deep(session, names=['multisite'], limit_to=['fvTenant', 'vzBrCP']) self.assertTrue(len(tenants) > 0) multisite_tenant = tenants[0] self.assertIsNone(multisite_tenant.get_child(Contract, 'Site1:multisite_mysqlcontract')) # Verify that the tag is removed in the remote site mtag = MultisiteTag('multisite_mysqlcontract', 'imported', 'Site1') self._verify_tag(session, 'multisite', str(mtag), exists=False) # Verify that the tag is removed locally session = self._login_session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD) mtag = MultisiteTag('multisite_mysqlcontract', 'exported', 'Site2') self._verify_tag(session, 'multisite', str(mtag), exists=False)
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(): # Setup or credentials and session description = ('Create 3 EPGs within the same Context, have them ' 'provide and consume contracts and attach them to ' 'a vmm domain.') 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 vdomain = EPGDomain.get_by_name(session,vmmdomain) # Create the Tenant tenant = Tenant(this_tenant) # 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) # 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) 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) ''' Define a contract with a single entry Additional entries can be added by duplicating the FilterEntry Push to APIC after each FilterEntry if it is not the last ''' contract1 = Contract('mysql-contract', tenant) entry1 = FilterEntry('SQL', applyToFrag='no', arpOpc='unspecified', dFromPort='3306', dToPort='3306', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract1) contract2 = Contract('app-contract', tenant) contract2.set_scope('application-profile') entry1 = FilterEntry('Flask', applyToFrag='no', arpOpc='unspecified', dFromPort='5000', dToPort='5000', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract2) tenant.push_to_apic(session) entry2 = FilterEntry('Flask2', applyToFrag='no', arpOpc='unspecified', dFromPort='5050', dToPort='5050', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract2) contract3 = Contract('web-contract', tenant) contract3.set_scope('application-profile') entry1 = FilterEntry('HTTPS', applyToFrag='no', arpOpc='unspecified', dFromPort='443', dToPort='443', etherT='ip', prot='tcp', tcpRules='unspecified', parent=contract3) # Provide the contract from 1 EPG and consume from the other t3_epg.provide(contract1) t2_epg.consume(contract1) t2_epg.provide(contract2) t1_epg.consume(contract2) t1_epg.provide(contract3) # 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.')
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
def __init__(self, session): print 'Getting configuration from APIC....' self.tenants = Tenant.get_deep(session) print 'Processing configuration....'
items["right"]["AppProfile"] = middle_right except: fatal("[E] Incorrect object format for the %s type." % args.type) # Now, we log into the APIC session = Session(args.url, args.login, args.password) response = session.login() if response.ok is False: print(response.content) sys.exit(1) # Retrieve Tenant data and split it into smaller components. Note that we # will keep reusing the "left" and "right" variables all the time until # we get to the object we need try: left = Tenant.get_deep(session, [items["left"]["Tenant"]])[0] left = split_tenant(left) right = Tenant.get_deep(session, [items["right"]["Tenant"]])[0] right = split_tenant(right) except: print("[E] Error, couldn't retrieve data from fabric") sys.exit(2) # Get the JSON output for the required left and right objects. # Level 1 objects if args.type == "Tenant": left = left["Tenant"] right = right["Tenant"] # Level 2 objects elif args.type in ["AppProfile", "BridgeDomain", "Context"]:
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(): """ Main show EPGs routine :return: None """ # Login to APIC description = ('Simple application that logs on to the APIC' ' and displays all of the EPGs.') creds = aci.Credentials('apic', description) args = creds.get() session = aci.Session(args.url, args.login, args.password) resp = session.login() if not resp.ok: print('%% Could not login to APIC') return # Download all of the tenants, app profiles, and EPGs # and store the names as tuples in a list tenants = Tenant.get_deep(session) tenants_list = [] for tenant in tenants: tenants_dict = {} tenants_dict['name'] = tenant.name if tenant.descr: tenants_dict['description'] = tenant.descr tenants_dict['app-profiles'] = [] for app in tenant.get_children(AppProfile): app_profiles = {} app_profiles['name'] = app.name if app.descr: app_profiles['description'] = app.descr app_profiles['epgs'] = [] for epg in app.get_children(EPG): epgs_info = {} epgs_info['name'] = epg.name if epg.descr: epgs_info['description'] = epg.descr epgs_info['endpoints'] = [] for endpoint in epg.get_children(Endpoint): endpoint_info = {} endpoint_info['name'] = endpoint.name if endpoint.ip != '0.0.0.0': endpoint_info['ip'] = endpoint.ip try: hostname = socket.gethostbyaddr(endpoint.ip)[0] except socket.error: hostname = None if hostname: endpoint_info['hostname'] = hostname if endpoint.descr: endpoint_info['description'] = endpoint.descr epgs_info['endpoints'].append(endpoint_info) app_profiles['epgs'].append(epgs_info) tenants_dict['app-profiles'].append(app_profiles) tenants_list.append(tenants_dict) tenants_info = {} tenants_info['tenants'] = tenants_list print yaml.safe_dump(tenants_info, sys.stdout, indent=4, default_flow_style=False)
def __init__(self, session, output, fh=None): self.tenants = Tenant.get_deep(session) self.output = output self.file = fh self.result = "Passed"
def main(): """ Main show EPGs routine :return: None """ # Login to APIC description = ('Simple application that logs on to the APIC' ' and displays all of the EPGs.') creds = aci.Credentials('apic', description) args = creds.get() session = aci.Session(args.url, args.login, args.password) resp = session.login() if not resp.ok: print('%% Could not login to APIC') # Download all of the tenants, app profiles, and EPGs # and store the names as tuples in a list tenants = Tenant.get_deep(session) tenants_list = [] for tenant in tenants: tenants_dict = {} tenants_dict['name'] = tenant.name if tenant.descr: tenants_dict['description'] = tenant.descr tenants_dict['app-profiles'] = [] for app in tenant.get_children(AppProfile): app_profiles = {} app_profiles['name'] =app.name if app.descr: app_profiles['description'] = app.descr app_profiles['epgs'] = [] for epg in app.get_children(EPG): epgs_info = {} epgs_info['name'] = epg.name if epg.descr: epgs_info['description'] = epg.descr epgs_info['endpoints'] = [] for endpoint in epg.get_children(Endpoint): endpoint_info = {} endpoint_info['name'] = endpoint.name if endpoint.ip != '0.0.0.0': endpoint_info['ip'] = endpoint.ip try: hostname = socket.gethostbyaddr(endpoint.ip)[0] except socket.error: hostname = None if hostname: endpoint_info['hostname'] = hostname if endpoint.descr: endpoint_info['description'] = endpoint.descr epgs_info['endpoints'].append(endpoint_info) app_profiles['epgs'].append(epgs_info) tenants_dict['app-profiles'].append(app_profiles) tenants_list.append(tenants_dict) tenants_info = {} tenants_info['tenants'] = tenants_list print yaml.safe_dump(tenants_info,sys.stdout, indent= 4,default_flow_style=False)
def __init__(self, session, output, fh=None): print('Getting configuration from APIC....') self.tenants = Tenant.get_deep(session) self.output = output self.file = fh print('Processing configuration....')
def _add_inherited_relation(self, tenants, epg, relation, deleted=False): tenant_found = False # Find the tenant. Add if necessary for tenant in tenants: if tenant.name == epg.tenant: tenant_found = True break if not tenant_found: tenant = Tenant(epg.tenant) tenants.append(tenant) # Find the EPG Container. Add if necessary if epg.is_l3out: epg_container_class = OutsideL3 else: epg_container_class = AppProfile epg_containers = tenant.get_children(only_class=epg_container_class) epg_container_found = False for epg_container in epg_containers: if epg_container.name == epg.epg_container_name: epg_container_found = True break if not epg_container_found: epg_container = epg_container_class(epg.epg_container_name, tenant) # Find the EPG. Add if necessary if epg.is_l3out: epg_class = OutsideEPG else: epg_class = EPG epgs = tenant.get_children(only_class=epg_class) epg_found = False for tenant_epg in epgs: if tenant_epg.name == epg.name: epg_found = True break if not epg_found: tenant_epg = epg_class(epg.name, epg_container) # Add the relation (relation_type, relation_name) = relation if relation_type == 'fvRsProv': contract = Contract(relation_name, tenant) tenant_epg.provide(contract) if deleted: tenant_epg.provide(contract) tenant_epg.dont_provide(contract) elif relation_type == 'fvRsCons': contract = Contract(relation_name, tenant) tenant_epg.consume(contract) if deleted: tenant_epg.consume(contract) tenant_epg.dont_consume(contract) elif relation_type == 'fvRsConsIf': contract_interface = ContractInterface(relation_name, tenant) tenant_epg.consume_cif(contract_interface) if deleted: tenant_epg.consume_cif(contract_interface) tenant_epg.dont_consume_cif(contract_interface) elif relation_type == 'fvRsProtBy': taboo = Taboo(relation_name, tenant) tenant_epg.protect(taboo) if deleted: tenant_epg.protect(taboo) tenant_epg.dont_protect(taboo) tenant_epg.add_tag('inherited:%s:%s' % (relation_type, relation_name)) if deleted: tenant_epg.delete_tag('inherited:%s:%s' % (relation_type, relation_name)) return tenants
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()))
# Process all relevant command-line parameters and print our welcome banner if args.debug is not None: debug_enable() print_banner() # Now, we log into the APIC session = Session(args.url, args.login, args.password) response = session.login() if response.ok is False: fatal(response.content) else: output("Successfully connected to %s" % args.url) # Retrieve the list of existing tenants tenants = Tenant.get(session) # Subscribe to each one urls=[] for tn in tenants: url = "/api/mo/uni/tn-%s.json?query-target=subtree&subscription=yes" % tn.name try: debug("Subscribing to '%s'" % url) session.subscribe(url, only_new=True) urls.append(url) except: error("Error creating subscription for tenant '%s'" % tn.name) # Also, subscribe to the Tenant class so we can create new subscriptions # if new tenants get created. tn_url = "/api/class/fvTenant.json?subscription=yes"