def test_node_get_parent_pod(self):
     session = self.login_to_apic()
     pods = Pod.get(session)
     pod = pods[0]
     nodes = Node.get(session, parent=pod)
     self.assertEqual(len(nodes), len(pod.get_children()))
     self.assertEqual(nodes[0].get_parent(), pod)
Example #2
0
def main():
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables
    description = ('Simple application that logs on to the APIC and displays'
                   ' the physical inventory.')
    creds = Credentials('apic', description)
    args = creds.get()

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        sys.exit(0)

    # Print the inventory of each Pod
    pods = Pod.get(session)
    for pod in pods:
        pod.populate_children(deep=True)
        pod_name = 'Pod: %s' % pod.name
        print(pod_name)
        print('=' * len(pod_name))
        print_inventory(pod)
 def test_node_get_parent_pod(self):
     session = self.login_to_apic()
     pods = Pod.get(session)
     pod = pods[0]
     nodes = Node.get(session, parent=pod)
     self.assertEqual(len(nodes), len(pod.get_children()))
     self.assertEqual(nodes[0].get_parent(), pod)
def main():
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables
    description = "Simple application that logs on to the APIC and displays" " the physical inventory."
    creds = Credentials("apic", description)
    args = creds.get()

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print("%% Could not login to APIC")
        sys.exit(0)

    # Print the inventory of each Pod
    pods = Pod.get(session)
    for pod in pods:
        pod.populate_children(deep=True)
        pod_name = "Pod: %s" % pod.name
        print(pod_name)
        print("=" * len(pod_name))
        print_inventory(pod)
    def test_populate_deep(self):
        session = self.login_to_apic()
        pods = Pod.get(session)
        pod = pods[0]
        pod.populate_children(deep=True)
        nodes = pod.get_children(Node)
        original_num_nodes = len(nodes)
        node_roles = set()
        for node in nodes:
            node_roles.add(node.get_role())
            if node.get_role() == 'spine' and node.fabricSt == 'active':
                spine = node
            if node.get_role() == 'controller' and node.fabricSt != 'inactive':
                controller = node

        self.assertEqual(len(node_roles ^ {'controller', 'spine', 'leaf'}), 0)

        modules = spine.get_children()
        module_types = set()
        for module in modules:
            module_types.add(module.get_type())
            if module.get_type() == 'linecard':
                linecard = module

        self.assertEqual(
            len(module_types
                ^ {'linecard', 'supervisor', 'powersupply', 'fantray'}), 0)

        interfaces = linecard.get_children()
        for interface in interfaces:
            self.assertIsInstance(interface, Interface)
        if linecard.model == 'N9K-X9736PQ':
            self.assertEqual(len(interfaces), 36)

        modules = controller.get_children()
        module_types = set()
        for module in modules:
            module_types.add(module.get_type())
        self.assertEqual(
            len(module_types ^ {'systemctrlcard', 'powersupply', 'fantray'}),
            0)

        links = pod.get_children(Link)
        for link in links:
            self.assertIsInstance(link, Link)
            self.assertIsInstance(link.node1, str)
            self.assertIsInstance(link.node2, str)
            self.assertIsInstance(link.slot1, str)
            self.assertIsInstance(link.slot2, str)
            self.assertIsInstance(link.port1, str)
            self.assertIsInstance(link.port2, str)
            self.assertIsInstance(link.link, str)

        # check that duplicate children are not populated
        pod.populate_children(deep=True)
        nodes = pod.get_children(Node)
        self.assertTrue(len(nodes) == original_num_nodes)
 def test_pod_valid_parent(self):
     """
     Tests that the parent class of the pod
     :return:
     """
     session = self.login_to_apic()
     parent = PhysicalModel()
     pod = Pod.get(session, parent)
     children = parent.get_children()
     self.assertEqual(pod, children)
 def test_pod_valid_parent(self):
     """
     Tests that the parent class of the pod
     :return:
     """
     session = self.login_to_apic()
     parent = PhysicalModel()
     pod = Pod.get(session, parent)
     children = parent.get_children()
     self.assertEqual(pod, children)
    def test_populate_deep(self):
        session = self.login_to_apic()
        pods = Pod.get(session)
        pod = pods[0]
        pod.populate_children(deep=True)
        nodes = pod.get_children(Node)
        original_num_nodes = len(nodes)
        node_roles = set()
        for node in nodes:
            node_roles.add(node.get_role())
            if node.get_role() == 'spine' and node.fabricSt == 'active':
                spine = node
            if node.get_role() == 'controller' and node.fabricSt != 'inactive':
                controller = node

        self.assertEqual(len(node_roles ^ {'controller', 'spine', 'leaf'}), 0)

        modules = spine.get_children()
        module_types = set()
        for module in modules:
            module_types.add(module.get_type())
            if module.get_type() == 'linecard':
                linecard = module

        self.assertEqual(len(module_types ^ {'linecard', 'supervisor', 'powersupply', 'fantray'}), 0)

        interfaces = linecard.get_children()
        for interface in interfaces:
            self.assertIsInstance(interface, Interface)
        if linecard.model == 'N9K-X9736PQ':
            self.assertEqual(len(interfaces), 36)

        modules = controller.get_children()
        module_types = set()
        for module in modules:
            module_types.add(module.get_type())
        self.assertEqual(len(module_types ^ {'systemctrlcard', 'powersupply', 'fantray'}), 0)

        links = pod.get_children(Link)
        for link in links:
            self.assertIsInstance(link, Link)
            self.assertIsInstance(link.node1, str)
            self.assertIsInstance(link.node2, str)
            self.assertIsInstance(link.slot1, str)
            self.assertIsInstance(link.slot2, str)
            self.assertIsInstance(link.port1, str)
            self.assertIsInstance(link.port2, str)
            self.assertIsInstance(link.link, str)

        # check that duplicate children are not populated
        pod.populate_children(deep=True)
        nodes = pod.get_children(Node)
        self.assertTrue(len(nodes) == original_num_nodes)
    def test_link_get_for_node(self):
        session = self.login_to_apic()
        pod = Pod.get(session)[0]
        links = Link.get(session)
        total_links = len(links)
        self.assertTrue(total_links > 0)
        self.assertRaises(TypeError, links[0].get_node1)
        self.assertRaises(TypeError, links[0].get_node2)
        self.assertRaises(TypeError, links[0].get_slot1)
        self.assertRaises(TypeError, links[0].get_slot2)
        self.assertRaises(TypeError, links[0].get_port1)
        self.assertRaises(TypeError, links[0].get_port2)
        links = Link.get(session, pod)
        self.assertEqual(len(links), total_links)
        switches = []
        for link in links:
            self.assertEqual(link.get_node1(), None)
            self.assertEqual(link.get_slot1(), None)
            self.assertEqual(link.get_port1(), None)
            self.assertEqual(link.get_node2(), None)
            self.assertEqual(link.get_slot2(), None)
            self.assertEqual(link.get_port2(), None)
            if link.node1 not in switches:
                switches.append(link.node1)
        self.assertTrue(len(switches) > 1)
        nodes = Node.get(session)
        spine = None
        for node in nodes:
            if node.get_role() == 'spine' and node.fabricSt == 'active':
                spine = node
                break
        if spine:
            links = Link.get(session, pod, spine.node)
            spine_links = len(links)
            self.assertTrue(spine_links > 0)
            self.assertTrue(spine_links < total_links)
            for link in links:
                self.assertEqual(link.node1, spine.node)
                self.assertIsInstance(str(link), str)
            links = Link.get(session, '1', spine.node)
            self.assertEqual(len(links), spine_links)

            self.assertNotEqual(links[0], links[1])
    def test_link_get_for_node(self):
        session = self.login_to_apic()
        pod = Pod.get(session)[0]
        links = Link.get(session)
        total_links = len(links)
        self.assertTrue(total_links > 0)
        self.assertRaises(TypeError, links[0].get_node1)
        self.assertRaises(TypeError, links[0].get_node2)
        self.assertRaises(TypeError, links[0].get_slot1)
        self.assertRaises(TypeError, links[0].get_slot2)
        self.assertRaises(TypeError, links[0].get_port1)
        self.assertRaises(TypeError, links[0].get_port2)
        links = Link.get(session, pod)
        self.assertEqual(len(links), total_links)
        switches = []
        for link in links:
            self.assertEqual(link.get_node1(), None)
            self.assertEqual(link.get_slot1(), None)
            self.assertEqual(link.get_port1(), None)
            self.assertEqual(link.get_node2(), None)
            self.assertEqual(link.get_slot2(), None)
            self.assertEqual(link.get_port2(), None)
            if link.node1 not in switches:
                switches.append(link.node1)
        self.assertTrue(len(switches) > 1)
        nodes = Node.get(session)
        spine = None
        for node in nodes:
            if node.get_role() == 'spine' and node.fabricSt == 'active':
                spine = node
                break
        if spine:
            links = Link.get(session, pod, spine.node)
            spine_links = len(links)
            self.assertTrue(spine_links > 0)
            self.assertTrue(spine_links < total_links)
            for link in links:
                self.assertEqual(link.node1, spine.node)
                self.assertIsInstance(str(link), str)
            links = Link.get(session, '1', spine.node)
            self.assertEqual(len(links), spine_links)

            self.assertNotEqual(links[0], links[1])
def main():
    """
    Main execution routine

    :return: None
    """
    description = ('Simple application that logs on to the APIC and displays'
                   ' the physical inventory.')

    # Login to APIC
    session = aci.Session(URL, LOGIN, PASSWORD)
    session.login()

    # Print the inventory of each Pod
    pods = Pod.get(session)
    for pod in pods:
        pod.populate_children(deep=True)
        pod_name = 'Pod: %s' % pod.name
        print(pod_name)
        print('=' * len(pod_name))
        print_inventory(pod)
def main(login,password,url):
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables
    description = ('Simple application that logs on to the APIC and displays'
                   ' the physical inventory.')
    #creds = Credentials('apic', description)
    #args1 = creds.get()
    #print type(args1)
    #print "args url ", args1.url
    #print "args user ", args1.login
    #print "args password", args1.password

    #url = 'http://172.31.216.24'
    #login = '******'
    #password = '******'

    # Login to APIC
    session = Session(url, login, password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        sys.exit(0)

    # Print the inventory of each Pod
    pods = Pod.get(session)
    for pod in pods:
        pod.populate_children(deep=True)
        pod_name = 'Pod: %s' % pod.name
        print(pod_name)
        print('=' * len(pod_name))
        print_inventory(pod)
def main(login, password, url):
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables
    description = ('Simple application that logs on to the APIC and displays'
                   ' the physical inventory.')
    #creds = Credentials('apic', description)
    #args1 = creds.get()
    #print type(args1)
    #print "args url ", args1.url
    #print "args user ", args1.login
    #print "args password", args1.password

    #url = 'http://172.31.216.24'
    #login = '******'
    #password = '******'

    # Login to APIC
    session = Session(url, login, password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        sys.exit(0)

    # Print the inventory of each Pod
    pods = Pod.get(session)
    for pod in pods:
        pod.populate_children(deep=True)
        pod_name = 'Pod: %s' % pod.name
        print(pod_name)
        print('=' * len(pod_name))
        print_inventory(pod)
Example #14
0
 def get_all_pods(self):
     session = self.login_to_apic()
     pods = Pod.get(session)
     self.assertTrue(len(pods) > 0)
     return pods, session
 def get_all_pods(self):
     session = self.login_to_apic()
     pods = Pod.get(session)
     self.assertTrue(len(pods) > 0)
     return pods, session