예제 #1
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()
예제 #2
0
    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))
예제 #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 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))
예제 #5
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)
예제 #6
0
    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)
예제 #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 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)
예제 #10
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)
예제 #11
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)
예제 #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 __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....')
예제 #14
0
                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"]:
예제 #15
0
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)
예제 #16
0
                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"]:
예제 #17
0
 def __init__(self, session):
     print 'Getting configuration from APIC....'
     self.tenants = Tenant.get_deep(session)
     print 'Processing configuration....'
예제 #18
0
파일: plugin.py 프로젝트: kecorbin/collins
 def __init__(self, session, output, fh=None):
     self.tenants = Tenant.get_deep(session)
     self.output = output
     self.file = fh
     self.result = "Passed"
예제 #19
0
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)
예제 #20
0
 def __init__(self, session):
     print 'Getting configuration from APIC....'
     self.tenants = Tenant.get_deep(session)
     print 'Processing configuration....'