def fabric_nodes_table(self, fabric_name):

        out = CommandTemplateExecutor(
            self._cli_service,
            command_template.FABRIC_NODES_SHOW,
            remove_prompt=True).execute_command(fabric_name=fabric_name)
        nodes_table = {}
        for line in out.splitlines():
            match = re.match(r'.+\:(.+)\:.+', line)
            if match:
                node_name = match.group(1).strip()
                nodes_table[node_name] = self._switch_info_table(node_name)
        return nodes_table
    def associations_table(self):
        out = CommandTemplateExecutor(self._cli_service,
                                      command_template.VLE_SHOW,
                                      remove_prompt=True).execute_command()

        associations_table = {}
        for line in out.splitlines():
            match = re.match(r'\s*(.+)\:(.+)\:(.+)\:(.+)\:(.+)\s*', line)
            if match:
                master_port = (match.group(2), match.group(4))
                slave_port = (match.group(3), match.group(5))
                associations_table[master_port] = slave_port
                associations_table[slave_port] = master_port
        return associations_table
Esempio n. 3
0
    def map_uni(self, src_port, dst_port):
        """
        Unidirectional mapping
        :param src_port: 
        :param dst_port: 
        :return:
        """

        if len(dst_port) > 1:
            raise Exception('Not supported')

        tap_src_port = src_port.split("/")[-1]
        tap_dst_port = dst_port[0].split("/")[-1]
        bidi_dst_port = None
        current_config = CommandTemplateExecutor(
            self._cli_service,
            command_template.GET_CURRENT_CONNECTIONS).execute_command()
        if tap_src_port in current_config:
            for line in current_config.splitlines():
                if tap_src_port in line:
                    ports = re.findall(r"[A-Z]\d+", line)
                    for prt in ports:
                        if prt != tap_src_port:
                            bidi_dst_port = prt
                    break
        if bidi_dst_port:
            output = CommandTemplateExecutor(
                self._cli_service, command_template.MAP_TAP).execute_command(
                    src_port=tap_src_port,
                    dst_port=bidi_dst_port,
                    tap_port=tap_dst_port)
        else:
            output = CommandTemplateExecutor(
                self._cli_service, command_template.MAP_UNI).execute_command(
                    src_port=src_port.split("/")[-1],
                    dst_port=dst_port[0].split("/")[-1])
        return output
    def port_table(self):
        """
        Port table
        :return:
        """

        map_types_dict = {">>": "uni", "<>": "bidi"}
        port_dict = dict()
        output = CommandTemplateExecutor(
            self._cli_service, command_template.PORT_NAMES).execute_command()
        port_list = re.findall(r"[A-Z]\d+", output)
        for port in port_list:
            port_info_dict = dict()
            port_info_dict["speed"] = ""
            port_info_dict["serial_number"] = ""
            port_info_dict["autoneg"] = ""
            port_info_dict["protocol"] = ""
            port_info_dict["protocol_type"] = ""
            port_info_dict["wavelength"] = ""
            port_info_dict["duplex"] = ""
            port_info_dict["rx_signal"] = ""
            port_info_dict["tx_signal"] = ""
            port_info = CommandTemplateExecutor(
                self._cli_service,
                command_template.PORT_INFO).execute_command(port_name=port)
            for port_info_line in port_info.splitlines():
                if "rate" in port_info_line.lower():
                    speed = port_info_line.split(":")[-1]
                    port_info_dict["speed"] = speed
                    port_info_dict["protocol_type"] = speed
                    continue

                if "protocol" in port_info_line.lower():
                    port_info_dict["protocol"] = port_info_line.split(
                        ":")[-1].strip()
                    continue

                if "wavelength" in port_info_line.lower():
                    port_info_dict["wavelength"] = port_info_line.split(
                        ":")[-1].strip()
                    continue

                if "serial" in port_info_line.lower():
                    port_info_dict["serial_number"] = port_info_line.split(
                        ":")[-1].strip()
                    continue

                if "rx signal" in port_info_line.lower():
                    port_info_dict["rx_signal"] = port_info_line.split(
                        ":")[-1].strip()
                    continue

                if "tx signal" in port_info_line.lower():
                    port_info_dict["tx_signal"] = port_info_line.split(
                        ":")[-1].strip()
                    continue

                if "autoneg" in port_info_line.lower():
                    port_info_dict["autoneg"] = port_info_line.split(
                        ":")[-1].strip()
                    continue

                if "connections" in port_info_line.lower():
                    # A31 Incoming_mapping = A15
                    # A15 Incoming mapping = A20
                    # A20 Incoming mapping = A15
                    map_info = port_info_line.split(":")[-1].strip()
                    match = self.PORT_CONNECTION_PATTERN.search(map_info)

                    if match:
                        src_port, connection_type, dst_port = match.groups()
                        map_type = map_types_dict.get(connection_type)

                        if map_type == 'uni' and dst_port == port:
                            mapped_port = Address(0,
                                                  map_info.split()[-1][:1],
                                                  src_port)
                        elif map_type == 'bidi':
                            mapped_port = Address(0,
                                                  map_info.split()[-1][:1],
                                                  dst_port)
                        else:
                            continue

                        port_info_dict["mapped_to"] = mapped_port

            port_dict[Address(0, port[:1], port)] = port_info_dict
        return port_dict