Ejemplo n.º 1
0
 def test_get_switches_multiple_param(self):
     """
     Test to return switches. Request is launched with multiple parameters of Ports = True and a specific
     fabric on my CFM system.
     """
     cfm.connect()
     test_switches = fabric.get_switches(cfm)
     cfm_fabric = test_switches[0]['fabric_uuid']
     test_switches = fabric.get_switches(cfm,
                                         params={
                                             'ports': True,
                                             'fabric': cfm_fabric
                                         })
     my_attributes = [
         'in_default_segment', 'ports', 'segment', 'fabric_uuid',
         'fitting_number', 'ip_gateway', 'hostip_state', 'ip_address_v6',
         'uuid', 'ip_mode', 'ip_gateway_v6', 'health', 'mac_address',
         'ip_mode_v6', 'serial_number', 'status', 'description',
         'ip_address', 'model', 'hw_revision', 'sw_version', 'name',
         'ip_mask', 'configuration_number', 'operational_stage',
         'ip_mask_v6'
     ]
     self.assertIs(type(test_switches), list)
     self.assertIs(type(test_switches[0]), dict)
     for i in test_switches[0].keys():
         self.assertIn(i, my_attributes)
Ejemplo n.º 2
0
 def test_get_switches_single_param(self):
     """
     Test to return switches. Request is launched with a single parameter of ports.
     """
     test_switches = fabric.get_switches(cfm, params={'ports': True})
     my_attributes = [
         'ports', 'segment', 'fabric_uuid', 'fitting_number', 'ip_gateway',
         'hostip_state', 'ip_address_v6', 'uuid', 'ip_mode',
         'ip_gateway_v6', 'health', 'mac_address', 'ip_mode_v6',
         'serial_number', 'status', 'description', 'ip_address', 'model',
         'hw_revision', 'sw_version', 'name', 'ip_mask',
         'configuration_number', 'operational_stage', 'ip_mask_v6'
     ]
     self.assertIs(type(test_switches), list)
     self.assertIs(type(test_switches[0]), dict)
     for i in test_switches[0].keys():
         self.assertIn(i, my_attributes)
Ejemplo n.º 3
0
 def test_get_ports(self):
     """
     """
     test_switches = fabric.get_switches(cfm)
     test_switch = test_switches[0]['uuid']
     ports_list = fabric.get_ports(cfm, test_switch)
     my_attributes = [
         'fec_mode', 'holddown', 'native_vlan', 'description',
         'speed_group', 'ungrouped_vlans', 'link_state', 'switch_uuid',
         'admin_state', 'form_factor', 'port_security_enabled', 'vlans',
         'speed', 'switch_name', 'fec', 'read_only', 'port_label', 'uuid',
         'is_uplink', 'vlan_group_uuids', 'name', 'permitted_qsfp_modes',
         'silkscreen', 'type', 'bridge_loop_detection', 'qsfp_mode'
     ]
     self.assertIs(type(ports_list), list)
     self.assertIs(type(ports_list[0]), dict)
     for i in ports_list[0].keys():
         self.assertIn(i, my_attributes)
Ejemplo n.º 4
0
 def test_get_switches(self):
     """
     Simple test to return switches. URL has no parameters
     :return:
     """
     test_switches = fabric.get_switches(cfm)
     my_attributes = [
         'segment', 'fabric_uuid', 'fitting_number', 'ip_gateway',
         'hostip_state', 'ip_address_v6', 'uuid', 'ip_mode',
         'ip_gateway_v6', 'health', 'mac_address', 'ip_mode_v6',
         'serial_number', 'status', 'description', 'ip_address', 'model',
         'hw_revision', 'sw_version', 'name', 'ip_mask',
         'configuration_number', 'operational_stage', 'ip_mask_v6'
     ]
     self.assertIs(type(test_switches), list)
     self.assertIs(type(test_switches[0]), dict)
     for i in test_switches[0].keys():
         self.assertIn(i, my_attributes)
Ejemplo n.º 5
0
    def test_add_fabric_ip_networks(self):
        """
        General test for pyhpecfm.fabric.add_fabric_ip_networks function
        """
        cfm.connect()
        fabric_uuid = fabric.get_fabrics(cfm)[0]['uuid']
        switch_uuid = fabric.get_switches(cfm)[0]['uuid']
        test_fabric = fabric.add_ip_fabric(cfm, fabric_uuid, 'new ip fabric',
                                           'my new fabric description',
                                           'manual', '172.16.0.0', '24', '10',
                                           switch_uuid, '172.16.0.1')

        my_attributes = [
            'subnet', 'fabric_uuid', 'name', 'switch_addresses', 'vlan',
            'uuid', 'mode', 'description'
        ]
        self.assertIs(type(test_fabric), dict)
        for i in test_fabric.keys():
            self.assertIn(i, my_attributes)
Ejemplo n.º 6
0
    def run(self):
        # Get switches from hpecfm controller.
        switches = fabric.get_switches(self.client)
        if isinstance(switches, list):
            # Setup a list for holding dictionaries
            switch_data = []
            # Iterate through switch data from CFM API
            for i in switches:
                # Build dictionary for return
                out = {
                    'u_health': i['health'],
                    'u_ip_address': i['ip_address'],
                    'u_mac_address': i['mac_address'],
                    'u_name': i['name'],
                    'u_sw_version': i['sw_version']
                }
                switch_data.append(out)

            return (True, switch_data)
        return (False, switches)
Ejemplo n.º 7
0
def main_select():
    #import cfm_api_utils as c
    ipaddress=request.form['ipaddress']
    user=request.form['user']
    passwd=request.form['passwd']

    # Authenticat to the controller
    client=CFMClient(ipaddress,user,passwd)
    client.connect()

    # Build database entry to save creds
    creds = Sidekick(user=user,passwd=passwd,ipaddress=ipaddress)
    # Save the record
    try:
        creds.save()
    except:
        error="ERR001 - Failed to save login credentials"
        return render_template('sidekick/dberror.html', error=error)


    # Turn on to build num db on initial run
    # num = 1
    # num = Number(num)
    # try:
        # creds.save()
    # except:
        # error = "ERR000 - Could not create number database"
        # return render_template('sidekick/dberror.html', error=error)


    # Returns a list a auto generated charts
    charts=build_charts()

    # Get the switches from the controller and save to the mongo database
    try:
        switches=fabric.get_switches(client)
    except:
        error="ERR-LOGIN - Failed to log into CFM controller"
        return render_template('sidekick/dberror.html', error=error)

    switch_data=[]
    # Process switch datat from plexxi API
    for switch in switches:
        health=switch['health']
        ip_address=switch['ip_address']
        mac_address=switch['mac_address']
        name=switch['name']
        sw_version=switch['sw_version']
        uuid=switch['uuid']

        # Write to switches database
        switch_info=Switches(health=health,ip_address=ip_address, mac_address=mac_address, name=name, sw_version=sw_version, uuid=uuid)
        # Save the record
        try:
            switch_info.save()
        except:
            error="ERR001X - Failed to save switch information"
            return render_template('sidekick/dberror.html', error=error)

        # Build list to write out to user interface
        out=[health,ip_address,mac_address,name,sw_version]
        switch_data.append(out)

    return render_template('main/sidekick1.html',u=user,i=ipaddress,g1_data=charts[0],g2_data=charts[1],s=switch_data)