コード例 #1
0
 def get_available_vlan_id(self, min_vlan, max_vlan):
     out = CommandTemplateExecutor(self._cli_service, command_template.VLAN_SHOW,
                                   remove_prompt=True).execute_command()
     switch_name_key = 'switch_name'
     vlan_id_key = 'vlan_id'
     vxlan_key = 'vxlan'
     description_key = 'description'
     out_list = ActionsHelper.parse_table_by_keys(out, switch_name_key, vlan_id_key, vxlan_key, description_key)
     busy_vlans = [int(data[vlan_id_key]) for data in out_list]
     available_vlan_id = list(set(range(min_vlan, max_vlan + 1)) - set(busy_vlans))[0]
     if available_vlan_id:
         return available_vlan_id
     raise Exception(self.__class__.__name__, 'Cannot determine available vlan id')
コード例 #2
0
    def vlan_id_for_port(self, node, port):
        out = CommandTemplateExecutor(self._cli_service,
                                      command_template.PORT_VLAN_INFO,
                                      remove_prompt=True).execute_command(
                                          node=node, port=port)
        node_key = 'node'
        port_key = 'port'
        vlan_id_key = 'vlan'

        out_table = ActionsHelper.parse_table_by_keys(out, node_key, port_key,
                                                      vlan_id_key)
        vlan_id = out_table[0].get(vlan_id_key)
        if vlan_id and vlan_id.lower() != 'none':
            return int(vlan_id)
コード例 #3
0
 def _validate_vlan_id_deletion(self, node_name, vlan_id):
     out = CommandTemplateExecutor(self._cli_service,
                                   command_template.VLAN_SHOW,
                                   remove_prompt=True).execute_command(
                                       node_name=node_name, vlan_id=vlan_id)
     vlan_id_key = 'vlan_id'
     switch_key = 'switch_key'
     vxlan_id_key = 'vxlan'
     out_table = ActionsHelper.parse_table_by_keys(out, vlan_id_key,
                                                   switch_key, vxlan_id_key)
     if out_table:
         raise CommandExecutionException(
             self.__class__.__name__,
             'Failed to delete vlan {} on node {}'.format(
                 vlan_id, node_name))
コード例 #4
0
 def _validate_vle_deletion(self, vle_name):
     vle_name_key = 'vle_name'
     node_1_key = 'node_1'
     node_2_key = 'node_2'
     node_1_port_key = 'node_1_port'
     node_2_port_key = 'node_2_port'
     status_key = 'status'
     out = CommandTemplateExecutor(
         self._cli_service,
         command_template.VLE_SHOW_FOR_NAME,
         remove_prompt=True).execute_command(vle_name=vle_name)
     out_table = ActionsHelper.parse_table_by_keys(
         out, vle_name_key, node_1_key, node_1_port_key, node_2_key,
         node_2_port_key, status_key)
     if out_table:
         raise CommandExecutionException(
             self.__class__.__name__,
             'Failed to delete VLE {}, see logs for more details'.format(
                 vle_name))
コード例 #5
0
 def _validate_vxlan_add(self, node_name, vxlan_id, tunnel):
     switch_key = 'switch'
     tunnel_name_key = 'tunnel_name'
     vxlan_id_key = 'vxlan_id'
     out = CommandTemplateExecutor(self._cli_service,
                                   command_template.VXLAN_SHOW,
                                   remove_prompt=True).execute_command(
                                       node_name=node_name,
                                       vxlan_id=vxlan_id)
     out_table = ActionsHelper.parse_table_by_keys(out, switch_key,
                                                   tunnel_name_key,
                                                   vxlan_id_key)
     active_tunnels = [record[tunnel_name_key] for record in out_table]
     if tunnel in active_tunnels:
         return
     raise CommandExecutionException(
         self.__class__.__name__,
         'Failed to add vxlan {} to tunnel {}, see driver logs for more details'
         .format(vxlan_id, tunnel))
コード例 #6
0
 def tunnels_table(self):
     out = CommandTemplateExecutor(self._cli_service, command_template.TUNNEL_INFO,
                                   remove_prompt=True).execute_command()
     switch_key = 'switch'
     tunnel_name_key = 'tunnel_name'
     local_ip_key = 'local_ip'
     remote_ip_key = 'remote_ip'
     # out_list = []
     # for line in out.splitlines():
     #     values = line.strip().split(':')
     #     if len(values) == 4:
     #         result = {switch_key: values[0], tunnel_name_key: values[1], local_ip_key: values[2],
     #                   remote_ip_key: values[3]}
     #         out_list.append(result)
     out_list = ActionsHelper.parse_table_by_keys(out, switch_key, tunnel_name_key, local_ip_key, remote_ip_key)
     switch_ip_table = {data[local_ip_key]: data[switch_key] for data in out_list}
     tunnels_table = {}
     for data_table in out_list:
         tunnel_nodes = (data_table[switch_key], switch_ip_table[data_table[remote_ip_key]])
         tunnels_table[tunnel_nodes] = data_table[tunnel_name_key]
     return tunnels_table
コード例 #7
0
    def _validate_port(self, node_name, port):
        out = CommandTemplateExecutor(self._cli_service,
                                      command_template.PORT_STATUS_SHOW,
                                      remove_prompt=True).execute_command(
                                          node_name=node_name, port=port)
        node_key = 'node'
        port_key = 'port'
        status_key = 'status'

        out_table = ActionsHelper.parse_table_by_keys(out, node_key, port_key,
                                                      status_key)
        if out_table:
            status_data = out_table[0].get(status_key)
            if status_data:
                for status in status_data.split(','):
                    if status.strip().lower(
                    ) in MappingActions.FORBIDDEN_PORT_STATUS_TABLE:
                        raise CommandExecutionException(
                            self.__class__.__name__,
                            'Port {} is not allowed to use for VLE, it has status {}'
                            .format((node_name, port), status))
コード例 #8
0
    def connection_table(self):
        out = CommandTemplateExecutor(self._cli_service,
                                      command_template.VLE_SHOW,
                                      remove_prompt=True).execute_command()

        vle_name_key = 'vle_name'
        node_1_key = 'node_1'
        node_2_key = 'node_2'
        node_1_port_key = 'node_1_port'
        node_2_port_key = 'node_2_port'
        connection_table = {}
        out_table = ActionsHelper.parse_table_by_keys(out, vle_name_key,
                                                      node_1_key, node_2_key,
                                                      node_1_port_key,
                                                      node_2_port_key)
        for record in out_table:
            src_record = (record[node_1_key], record[node_1_port_key])
            dst_record = (record[node_2_key], record[node_2_port_key])
            vle_name = record[vle_name_key]
            connection_table[src_record] = (dst_record, vle_name)
            connection_table[dst_record] = (src_record, vle_name)
        return connection_table
コード例 #9
0
 def _switch_info_table(self, switch_name):
     out = CommandTemplateExecutor(
         self._cli_service,
         command_template.SWITCH_INFO,
         remove_prompt=True).execute_command(switch_name=switch_name)
     return ActionsHelper.parse_table(out)
コード例 #10
0
 def get_fabric_info(self):
     out = CommandTemplateExecutor(self._cli_service, command_template.FABRIC_INFO,
                                   remove_prompt=True).execute_command()
     return ActionsHelper.parse_table(out)