コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
    def test_node_get_parent_pod_id(self):
        session = self.login_to_apic()
        pod = '1'
        nodes = Node.get(session, parent=pod)

        self.assertTrue(len(nodes) > 0)
        self.assertEqual(nodes[0].get_parent(), None)
コード例 #4
0
def show_basic_node():
    from acitoolkit.aciphysobject import Node
    if not connected():
        if not collect_login():
            return

    data = []

    # Get and print all of the items from the APIC
    items = Node.get(session)
    for item in items:
        if item.role == 'controller':
            item.role = 'APIC'
        data.append((item.serial, item.role, item.node, item.health,
                     item.model, item.oob_mgmt_ip, item.tep_ip))

    newdata = sorted(data, key=lambda x: x[1])
    # Display the data downloaded
    template = "{0:15} {1:7} {2:6} {3:8} {4:17} {5:15} {6:15}"
    print template.format("Serial Number", "Role", "Node", "Health", "Model",
                          "OOB Address", "TEP Address")
    print template.format("-------------", "-----", "----", "------",
                          "---------------", "-------------",
                          "---------------")
    for rec in newdata:

        print template.format(*rec)
コード例 #5
0
def show_basic_node():
    from acitoolkit.aciphysobject import Node
    if not connected():
        if not collect_login():
            return

    data = []

    # Get and print all of the items from the APIC
    items = Node.get(session)
    for item in items:
        if item.role == 'controller':
            item.role = 'APIC'
        data.append((item.serial,
                   item.role,
                   item.node,
                   item.health,
                   item.model,
                   item.oob_mgmt_ip,
                   item.tep_ip))
    
    newdata = sorted(data,key=lambda x: x[1])
    # Display the data downloaded
    template = "{0:15} {1:7} {2:6} {3:8} {4:17} {5:15} {6:15}"
    print template.format("Serial Number", "Role", "Node", "Health", "Model", "OOB Address", "TEP Address")
    print template.format("-------------", "-----", "----", "------", "---------------", "-------------", "---------------")
    for rec in newdata:
    
        print template.format(*rec)
コード例 #6
0
    def test_node_get_parent_pod_id(self):
        session = self.login_to_apic()
        pod = '1'
        nodes = Node.get(session, parent=pod)

        self.assertTrue(len(nodes) > 0)
        self.assertEqual(nodes[0].get_parent(), None)
コード例 #7
0
def get_leafs(session):
    from acitoolkit.aciphysobject import Node
    data = []

    items = Node.get(session)
    for item in items:
        if item.role == 'leaf':
            data.append(item.node)

    return data
コード例 #8
0
    def test_node(self):
        session = self.login_to_apic()
        nodes = Node.get(session)

        for node in nodes:
            self.assertIsInstance(node.get_name(), str)
            self.assertTrue(len(node.get_name()) > 0)

            self.assertEqual(node.get_type(), "node")

            self.assertIsInstance(node.get_pod(), str)
            self.assertTrue(len(node.get_pod()) > 0)

            self.assertIsInstance(node.get_node(), str)
            self.assertTrue(len(node.get_node()) > 0)

            self.assertIn(node.get_role(), ["controller", "leaf", "spine"])
            self.assertIn(node.getFabricSt(), ["active", "inactive", "unknown"])
コード例 #9
0
    def test_node(self):
        session = self.login_to_apic()
        nodes = Node.get(session)

        for node in nodes:
            self.assertIsInstance(node.get_name(), str)
            self.assertTrue(len(node.get_name()) > 0)

            self.assertEqual(node.get_type(), 'node')

            self.assertIsInstance(node.get_pod(), str)
            self.assertTrue(len(node.get_pod()) > 0)

            self.assertIsInstance(node.get_node(), str)
            self.assertTrue(len(node.get_node()) > 0)

            self.assertIn(node.get_role(), ['controller', 'leaf', 'spine'])
            self.assertIn(node.getFabricSt(), ['active', 'inactive', 'unknown'])
コード例 #10
0
    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])
コード例 #11
0
    def test_node(self):
        session = self.login_to_apic()
        nodes = Node.get(session)

        for node in nodes:
            self.assertIsInstance(node.get_name(), str)
            self.assertTrue(len(node.get_name()) > 0)

            self.assertEqual(node.get_type(), 'node')

            self.assertIsInstance(node.get_pod(), str)
            self.assertTrue(len(node.get_pod()) > 0)

            self.assertIsInstance(node.get_node(), str)
            self.assertTrue(len(node.get_node()) > 0)

            self.assertIn(node.get_role(), ['controller', 'leaf', 'spine'])
            self.assertIn(node.getFabricSt(),
                          ['active', 'inactive', 'unknown'])
コード例 #12
0
    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])
コード例 #13
0
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)

    nodes = Node.get(session)
    for node in nodes:
        print('=' * 50)
        print('Pod: {}'.format(node.pod))
        print('Node: {}'.format(node.node))
        print('Mode: {}'.format(node.mode))
        print('Model: {}'.format(node.model))
        print('Vendor: {}'.format(node.vendor))
        print('Serial: {}'.format(node.serial))
コード例 #14
0
 def test_get_all_nodes(self):
     pods, session = self.get_all_pods()
     for pod in pods:
         nodes = Node.get(session)
         self.assertTrue(len(nodes) > 0)
         self.assertTrue(pod.get_serial() is None)
コード例 #15
0
def collect_add_server_EPG():
    from acitoolkit.aciphysobject import Node

    if not collect_login():
        return False

    tenants_list = []
    apps_list = []
    epgs_list = []
    
    print '\n\n'
    print '====================================='
    print '==  Add physcial server to an EPG  =='
    print '=====================================\n'

    
    tenants = ACI.Tenant.get(session)
    for tenant in tenants:
        tenants_list.append((tenant.name))
    
    for a in range(len(tenants_list)):
        print str(a) + ': ' + tenants_list[a]

    input = raw_input('\nEnter the Tenant #: ')
    tenant_in = 99
    try:
        tenant_in = int(input)
    except:
        pass
    
    print '\n'
    apps = ACI.AppProfile.get(session, tenants[tenant_in])
    for app in apps:
        apps_list.append((app.name))
    
    if len(apps) <= 0:
        error_message([2,'There are no applications in this Tenant yet', 2])
        return
    for a in range(len(apps_list)):
            print str(a) + ': ' + apps_list[a]

    input = raw_input('\nEnter the Application Profile #: ')
    app_in = 99
    try:
        app_in = int(input)
    except:
        pass

    print '\n'
    
    epgs = ACI.EPG.get(session, apps[app_in], tenants[tenant_in])
    if len(epgs) <= 0:
        error_message([3,'There are no EPGs in this Application yet', 2])
        return
        
    for epg in epgs:
        epgs_list.append((epg.name))
        
    for a in range(len(epgs_list)):
        print str(a) + ': ' + epgs_list[a]

    input = raw_input('\nEnter the End Point Group #: ')
    epg_in = 99
    try:
        epg_in = int(input)
    except:
        pass

    # Select the leaf node
    print '\n'
    leafs = Node.get(session)
    
    if len(leafs) <= 0:
        error_message([3,'You have no Leafs!', 2])
        return

    leafs_list = []
    for leaf in leafs:
        if leaf.model == 'APIC': continue
        if leaf.role == 'spine': continue
        
        leafs_list.append((leaf.node))
    
    for a in range(len(leafs_list)):
        print str(a) + ': ' + leafs_list[a]

    input = raw_input('\nEnter the leaf number where the new server is located #: ')
    leaf_in = 99
    try:
        leaf_in = int(input)
    except:
        pass

    # Enter the interface
    print '\n'

    input = raw_input('\nEnter the interface number the new server is attached too #: ')
    if_in = 999
    try:
        if_in = int(input)
    except:
        pass

    # Enter the interface
    print '\n'

    input = raw_input('\nEnter the VLAN number (this interface will be a tagged interface but can be changed in the APIC GUI later): ')
    vlan_in = 999
    try:
        vlan_in = int(input)
    except:
        pass


    interface = {'type': 'eth',
                 'pod': '1', 
                 'node': str(leafs_list[leaf_in]), 
                 'module': '1', 
                 'port': str(if_in)}
    vlan = {'name': 'vlan' + str(vlan_in),
            'encap_type': 'vlan',
            'encap_id': str(vlan_in)}

    input = raw_input('\nPress Enter to continue.')
    create_add_server_EPG(tenants[tenant_in],apps[app_in],epgs[epg_in],interface,vlan)
コード例 #16
0
 def get_spine(self):
     session = self.login_to_apic()
     nodes = Node.get(session)
     for node in nodes:
         if node.get_role() == "spine" and node.fabricSt == "active":
             return node, session
コード例 #17
0
 def test_get_all_nodes(self):
     pods, session = self.get_all_pods()
     for pod in pods:
         nodes = Node.get(session)
         self.assertTrue(len(nodes) > 0)
         self.assertTrue(pod.get_serial() is None)
コード例 #18
0
def collect_add_server_EPG():
    from acitoolkit.aciphysobject import Node

    if not collect_login():
        return False

    tenants_list = []
    apps_list = []
    epgs_list = []

    print '\n\n'
    print '====================================='
    print '==  Add physcial server to an EPG  =='
    print '=====================================\n'

    tenants = ACI.Tenant.get(session)
    for tenant in tenants:
        tenants_list.append((tenant.name))

    for a in range(len(tenants_list)):
        print str(a) + ': ' + tenants_list[a]

    input = raw_input('\nEnter the Tenant #: ')
    tenant_in = 99
    try:
        tenant_in = int(input)
    except:
        pass

    print '\n'
    apps = ACI.AppProfile.get(session, tenants[tenant_in])
    for app in apps:
        apps_list.append((app.name))

    if len(apps) <= 0:
        error_message([2, 'There are no applications in this Tenant yet', 2])
        return
    for a in range(len(apps_list)):
        print str(a) + ': ' + apps_list[a]

    input = raw_input('\nEnter the Application Profile #: ')
    app_in = 99
    try:
        app_in = int(input)
    except:
        pass

    print '\n'

    epgs = ACI.EPG.get(session, apps[app_in], tenants[tenant_in])
    if len(epgs) <= 0:
        error_message([3, 'There are no EPGs in this Application yet', 2])
        return

    for epg in epgs:
        epgs_list.append((epg.name))

    for a in range(len(epgs_list)):
        print str(a) + ': ' + epgs_list[a]

    input = raw_input('\nEnter the End Point Group #: ')
    epg_in = 99
    try:
        epg_in = int(input)
    except:
        pass

    # Select the leaf node
    print '\n'
    leafs = Node.get(session)

    if len(leafs) <= 0:
        error_message([3, 'You have no Leafs!', 2])
        return

    leafs_list = []
    for leaf in leafs:
        if leaf.model == 'APIC': continue
        if leaf.role == 'spine': continue

        leafs_list.append((leaf.node))

    for a in range(len(leafs_list)):
        print str(a) + ': ' + leafs_list[a]

    input = raw_input(
        '\nEnter the leaf number where the new server is located #: ')
    leaf_in = 99
    try:
        leaf_in = int(input)
    except:
        pass

    # Enter the interface
    print '\n'

    input = raw_input(
        '\nEnter the interface number the new server is attached too #: ')
    if_in = 999
    try:
        if_in = int(input)
    except:
        pass

    # Enter the interface
    print '\n'

    input = raw_input(
        '\nEnter the VLAN number (this interface will be a tagged interface but can be changed in the APIC GUI later): '
    )
    vlan_in = 999
    try:
        vlan_in = int(input)
    except:
        pass

    interface = {
        'type': 'eth',
        'pod': '1',
        'node': str(leafs_list[leaf_in]),
        'module': '1',
        'port': str(if_in)
    }
    vlan = {
        'name': 'vlan' + str(vlan_in),
        'encap_type': 'vlan',
        'encap_id': str(vlan_in)
    }

    input = raw_input('\nPress Enter to continue.')
    create_add_server_EPG(tenants[tenant_in], apps[app_in], epgs[epg_in],
                          interface, vlan)
コード例 #19
0
 def get_controller(self):
     session = self.login_to_apic()
     nodes = Node.get(session)
     for node in nodes:
         if node.get_role() == 'controller' and node.fabricSt != 'inactive':
             return node, session
コード例 #20
0
 def test_exists_node(self):
     session = self.login_to_apic()
     nodes = Node.get(session)
     self.assertTrue(Node.exists(session, nodes[0]))
     nodes[0].node = '999'
     self.assertFalse(Node.exists(session, nodes[0]))
コード例 #21
0
 def get_leaf(self):
     session = self.login_to_apic()
     nodes = Node.get(session)
     for node in nodes:
         if node.get_role() == 'leaf' and node.fabricSt == 'active':
             return node, session
コード例 #22
0
 def get_leaf(self):
     session = self.login_to_apic()
     nodes = Node.get(session)
     for node in nodes:
         if node.get_role() == 'leaf' and node.fabricSt == 'active':
             return node, session
コード例 #23
0
 def get_controller(self):
     session = self.login_to_apic()
     nodes = Node.get(session)
     for node in nodes:
         if node.get_role() == 'controller' and node.fabricSt != 'inactive':
             return node, session
コード例 #24
0
 def test_exists_node(self):
     session = self.login_to_apic()
     nodes = Node.get(session)
     self.assertTrue(Node.exists(session, nodes[0]))
     nodes[0].node = '999'
     self.assertFalse(Node.exists(session, nodes[0]))
コード例 #25
0
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