def ports_table(self):
        """
        :rtype: dict
        """
        port_table = {}
        port_logic_output = CommandTemplateExecutor(
            self._cli_service,
            command_template.PORT_SHOW_LOGIC_TABLE).execute_command()

        for record in CommandActionsHelper.parse_table(
                port_logic_output.strip(), r'^\w+\s+\d+\s+\w+\s+e\d+\s+w\d+$'):
            port_table[record[1]] = {'blade': record[2]}

        port_output = CommandTemplateExecutor(
            self._cli_service, command_template.PORT_SHOW).execute_command()

        for record in CommandActionsHelper.parse_table(
                port_output.strip(), r'^e\d+\s+\d+\s+\d+\s+\d+\s+w\d+\s+.*$'):
            record_id = re.sub(r'\D', '', record[0])
            if record_id in port_table:
                port_table[record_id]['locked'] = record[1]
                if len(record) > 7:
                    port_table[record_id]['connected'] = re.sub(
                        r'\D', '', record[5])
                else:
                    port_table[record_id]['connected'] = None
        return port_table
示例#2
0
    def board_table(self):
        """
        :rtype: dict
        """
        board_table = {}
        info_out = CommandTemplateExecutor(self._cli_service, command_template.SWITCH_INFO).execute_command()

        board_table.update(self._parse_data(info_out.strip()))

        sw_version_out = CommandTemplateExecutor(self._cli_service, command_template.SOFTWARE_VERSION).execute_command()
        board_table.update(self._parse_data(sw_version_out.strip()))

        sw_setup_out = CommandTemplateExecutor(self._cli_service, command_template.SWITCH_SETUP).execute_command()
        board_table.update(self._parse_data(sw_setup_out.strip()))

        return board_table
    def ports_info(self, *port_ids):
        self._logger.debug('Getting ports info for ports {}'.format(', '.join(port_ids)))
        port_output = CommandTemplateExecutor(self._cli_service,
                                              command_template_autoload.PORT_SHOW).execute_command()
        ports_info = []

        for port_id in port_ids:
            pattern = r'^\D{0}\s+\d+\s+\d+\s+\d+\s+\D{0}.*$'.format(port_id)
            match_list = CommandActionsHelper.parse_table(port_output.strip(), pattern)
            east_port = None
            west_port = None
            for record in match_list:
                name = record[0]
                connected = re.sub(r'\D', '', record[5]) if record[2] == '2' else None
                locked = record[1] == '2'
                disabled = record[3] == '2'
                paired = record[4]
                port = Port(name, paired, connected, locked, disabled)
                if re.match(r'e', port.name, re.IGNORECASE):
                    east_port = port
                elif re.match(r'w', port.name, re.IGNORECASE):
                    west_port = port
            if east_port and west_port:
                ports_info.append(PortInfo(port_id, east_port, west_port))
            else:
                raise Exception(self.__class__.__name__, 'Cannot collect information for port {}'.format(port_id))

        return ports_info
 def get_state_id(self):
     state_id = CommandTemplateExecutor(self._cli_service, command_template.GET_STATE_ID).execute_command()
     return re.split(r'\s', state_id.strip())[1]