Пример #1
0
 def test_get_lags_multiple_param(self):
     """
     Test to return lags. Passing multiple params.
     """
     test_lags = fabric.get_lags(cfm,
                                 params={
                                     'count_only': False,
                                     'mac_attachments': False,
                                     'mac_learnining': True,
                                     'ports': True,
                                     'port_type': 'access',
                                     'tag': True,
                                     'type': 'provisioned',
                                     'vlan_groups': True
                                 })
     my_attributes = [
         'native_vlan', 'fabric_uuid', 'uuid', 'tags', 'vlan_groups',
         'mac_learning_use_default_configuration',
         'mac_learning_configuration', 'mac_learning_attachments',
         'description', 'vlan_group_uuids', 'lacp-fallback',
         'port_properties', 'vlans', 'type', 'ungrouped_vlans', 'name'
     ]
     self.assertIs(type(test_lags), list)
     self.assertIs(type(test_lags[0]), dict)
     for i in test_lags[0].keys():
         self.assertIn(i, my_attributes)
Пример #2
0
 def test_get_lags_no_params(self):
     """
     Test case for pyhpecfm.fabric get_lags function no parameters
     """
     test_lags = fabric.get_lags(cfm)
     my_attributes = [
         'native_vlan', 'fabric_uuid', 'uuid', 'tags', 'vlan_groups',
         'mac_learning_use_default_configuration',
         'mac_learning_configuration', 'mac_learning_attachments',
         'description', 'vlan_group_uuids', 'lacp-fallback',
         'port_properties', 'vlans', 'type', 'ungrouped_vlans', 'name'
     ]
     self.assertIs(type(test_lags), list)
     self.assertIs(type(test_lags[0]), dict)
     for i in test_lags[0].keys():
         self.assertIn(i, my_attributes)
Пример #3
0
 def run(self,
         count_only=None,
         mac_attachments=None,
         mac_learning=None,
         ports=None,
         port_type=None,
         tag=None,
         type=None,
         vlan_groups=None):
     params = {
         'count_only': count_only,
         'mac_attachemnts': mac_attachments,
         'mac_learning': mac_learning,
         'ports': ports,
         'port_type': port_type,
         'tag': tag,
         'type': type,
         'vlan_groups': vlan_groups
     }
     cfm_lags = fabric.get_lags(self.client, params)
     return (True, cfm_lags)
Пример #4
0
from pyhpecfm.client import CFMClient
from pyhpecfm import fabric

ipaddress = '172.18.1.66'
username = '******'
password = '******'

client = CFMClient(ipaddress, username, password)
client.connect()

params = {
    'count_only': False,
    'mac_attachemnts': False,
    'mac_learning': True,
    'ports': True,
    'port_type': 'access',
    'tag': True,
    'type': 'provisioned',
    'vlan_groups': True
}
cfm_lags = fabric.get_lags(client, params)
print cfm_lags
def process_lags():

    # Get a client connection.
    client = access_client()

    # assignment of attributes
    count_only = False
    mac_attachments = True
    mac_learning = True
    ports = True
    port_type = 'access'
    tags = True
    type = 'provisioned'
    vlan_groups = True
    # Create an attribute dictionary
    params = {
        'count_only': count_only,
        'mac_attachments': mac_attachments,
        'mac_learning': mac_learning,
        'ports': ports,
        'port_type': port_type,
        'tags': tags,
        'type': type,
        'vlan_groups': vlan_groups
    }

    # Pull the CFM controller for all lags
    try:
        cfm_lags = fabric.get_lags(client, params)
    except:
        error = "ERR-LOGIN - Failed to log into CFM controller"
        return error

    # build properties and ports disctionaries
    # Create some empty lists
    port_props = []
    port_detail = []
    lag_group = []
    for lag in cfm_lags:
        if len(lag['port_properties']) > 1:

            # Iterate through port_properties
            for item in lag['port_properties']:
                lag_mode = item['lacp']['mode']
                lag_speed = item['speed']['current']
                lag_partner_status = item['port_lacp_state'][0][
                    'partner_state_lacp_status']
                lag_partner_system = item['port_lacp_state'][0][
                    'partner_state_system_id']
                lag_partner_port_state = item['port_lacp_state'][0][
                    'partner_state_port']
                actor_lacp_status = item['port_lacp_state'][0][
                    'actor_state_lacp_status']
                # Define properties dictionary
                properties = {
                    'mode': lag_mode,
                    'speed': lag_speed,
                    'partner_status': lag_partner_status,
                    'partner_system': lag_partner_system,
                    'partner_port_state': lag_partner_port_state,
                    'actor_status': actor_lacp_status
                }

                # Extract port detail.
                for ports in item['ports']:
                    switch_name = ports['switch_name']
                    link_state = ports['link_state']
                    admin_state = ports['admin_state']
                    port_security_enabled = ports['port_security_enabled']
                    vlans = ports['vlans']
                    speed = ports['speed']
                    port_label = ports['port_label']
                    bridge_loop_detection = ports['bridge_loop_detection']
                # Define port dictionary
                port_information = {
                    'switch_name': switch_name,
                    'link_state': link_state,
                    'admin_state': admin_state,
                    'port_security_enabled': port_security_enabled,
                    'vlans': vlans,
                    'speed': speed,
                    'port_label': port_label,
                    'bridge_loop_detection': bridge_loop_detection
                }

                port_detail.append(port_information)
                #ports = {'ports':port_detail}
            #----add port detail to the dictionary items
            properties['ports'] = port_detail
            properties['name'] = lag['name']
            # Now make it a dictionary
            properties = {'properties': properties}

            lag_group.append(properties)

        lag_data = []
        port_props = []
        port_detail = []
    return render_template('lags/lags.html', l=lag_group)