Beispiel #1
0
    def map_clear(self, ports):
        """Remove simplex/multi-cast/duplex connection ending on the destination port.

        :param ports: ports, ['192.168.42.240:A/A/21', '192.168.42.240:A/A/22']
        :type ports: list
        :return: None
        :raises Exception: if command failed
        """
        self._logger.info('MapClear, Ports: {}'.format(', '.join(ports)))
        port_names = map(self._convert_cs_port_to_port_name, ports)

        with self._get_cli_services_lst() as cli_services_lst:
            mapping_actions = MappingActions(
                cli_services_lst,
                self._logger,
                self._mapping_timeout,
                self._mapping_check_delay,
            )
            system_actions = SystemActions(cli_services_lst, self._logger)
            port_table = system_actions.get_port_table()
            connected_ports = port_table.get_connected_port_pairs(port_names,
                                                                  bidi=True)
            mapping_actions.disconnect(connected_ports)

            port_table = system_actions.get_port_table()
            connected_ports = port_table.get_connected_port_pairs(port_names,
                                                                  bidi=True)
            if connected_ports:
                connected_port_names = [(src.name, dst.name)
                                        for src, dst in connected_ports]
                raise BaseRomeException(
                    "Cannot disconnect all ports. Ports: {} left connected".
                    format(', '.join(map(' - '.join, connected_port_names))))
Beispiel #2
0
    def map_uni(self, src_port, dst_ports):
        """Unidirectional mapping of two ports.

        :param src_port: src port address, '192.168.42.240:B/B/21'
        :type src_port: str
        :param dst_ports: list of dst ports addresses,
            ['192.168.42.240:B/B/22', '192.168.42.240:B/B/23']
        :type dst_ports: list
        :return: None
        :raises Exception: if command failed
        """
        if len(dst_ports) != 1:
            raise BaseRomeException(
                'MapUni operation is not allowed for multiple Dst ports')
        _, letter = self._split_addresses_and_letter(src_port)
        if letter.startswith('Q'):
            raise NotSupportedError("MapUni for matrix Q doesn't supported")
        self._logger.info('MapUni, SrcPort: {0}, DstPort: {1}'.format(
            src_port, dst_ports[0]))

        src_port_name = self._convert_cs_port_to_port_name(src_port)
        dst_port_name = self._convert_cs_port_to_port_name(dst_ports[0])

        with self._get_cli_services_lst() as cli_services_lst:
            system_actions = SystemActions(cli_services_lst, self._logger)
            mapping_actions = MappingActions(
                cli_services_lst,
                self._logger,
                self._mapping_timeout,
                self._mapping_check_delay,
            )
            port_table = system_actions.get_port_table()
            src_logic_port = port_table[src_port_name]
            dst_logic_port = port_table[dst_port_name]

            if port_table.is_connected(src_logic_port, dst_logic_port):
                self._logger.debug('Ports {} and {} already connected'.format(
                    src_port_name, dst_port_name))
                return

            port_table.verify_ports_for_connection(src_logic_port,
                                                   dst_logic_port)
            mapping_actions.connect(src_logic_port, dst_logic_port, bidi=False)

            port_table = system_actions.get_port_table()
            src_logic_port = port_table[src_port_name]
            dst_logic_port = port_table[dst_port_name]

            if not port_table.is_connected(src_logic_port, dst_logic_port):
                raise ConnectionPortsError(
                    'Cannot connect port {} to port {} during {}sec'.format(
                        src_port_name, dst_port_name, self._mapping_timeout))
Beispiel #3
0
    def map_clear_to(self, src_port, dst_ports):
        """Remove simplex/multi-cast/duplex connection ending on the destination port.

        :param src_port: src port address, '192.168.42.240:A/A/21'
        :type src_port: str
        :param dst_ports: list of dst ports addresses,
            ['192.168.42.240:A/A/21', '192.168.42.240:A/A/22']
        :type dst_ports: list
        :return: None
        :raises Exception: if command failed
        """
        if len(dst_ports) != 1:
            raise BaseRomeException(
                'MapClearTo operation is not allowed for multiple Dst ports')

        self._logger.info('MapClearTo, SrcPort: {0}, DstPort: {1}'.format(
            src_port, dst_ports[0]))

        src_port_name = self._convert_cs_port_to_port_name(src_port)
        dst_port_name = self._convert_cs_port_to_port_name(dst_ports[0])

        with self._get_cli_services_lst() as cli_services_lst:
            mapping_actions = MappingActions(
                cli_services_lst,
                self._logger,
                self._mapping_timeout,
                self._mapping_check_delay,
            )
            system_actions = SystemActions(cli_services_lst, self._logger)
            port_table = system_actions.get_port_table()
            connected_ports = port_table.get_connected_port_pairs(
                [src_port_name])

            if not connected_ports:
                self._logger.debug("Ports already disconnected.")
                return

            src_logic_port, dst_logic_port = next(iter(connected_ports))
            if dst_logic_port.name != dst_port_name:
                raise BaseRomeException(
                    "Source port connected to another port - {}".format(
                        dst_logic_port.name))
            mapping_actions.disconnect(connected_ports)

            port_table = system_actions.get_port_table()
            connected_ports = port_table.get_connected_port_pairs(
                [src_port_name])
            if connected_ports:
                raise BaseRomeException("Cannot disconnect ports: {}".format(
                    ' - '.join((src_logic_port.name, dst_logic_port.name))))
Beispiel #4
0
    def map_bidi(self, src_port, dst_port):
        """Create a bidirectional connection between source and destination ports.

        :param src_port: src port address, '192.168.42.240:A/A/21'
        :type src_port: str
        :param dst_port: dst port address, '192.168.42.240:A/A/22'
        :type dst_port: str
        :return: None
        :raises Exception: if command failed
        """
        self._logger.info('MapBidi, SrcPort: {0}, DstPort: {1}'.format(
            src_port, dst_port))
        src_port_name = self._convert_cs_port_to_port_name(src_port)
        dst_port_name = self._convert_cs_port_to_port_name(dst_port)

        with self._get_cli_services_lst() as cli_services_lst:
            mapping_actions = MappingActions(
                cli_services_lst,
                self._logger,
                self._mapping_timeout,
                self._mapping_check_delay,
            )
            system_actions = SystemActions(cli_services_lst, self._logger)
            port_table = system_actions.get_port_table()
            src_logic_port = port_table[src_port_name]
            dst_logic_port = port_table[dst_port_name]

            if port_table.is_connected(src_logic_port,
                                       dst_logic_port,
                                       bidi=True):
                self._logger.debug('Ports {} and {} already connected'.format(
                    src_port_name, dst_port_name))
                return

            port_table.verify_ports_for_connection(src_logic_port,
                                                   dst_logic_port,
                                                   bidi=True)

            try:
                mapping_actions.connect(src_logic_port,
                                        dst_logic_port,
                                        bidi=True)

                port_table = system_actions.get_port_table()
                src_logic_port = port_table[src_port_name]
                dst_logic_port = port_table[dst_port_name]

                is_connected = port_table.is_connected(src_logic_port,
                                                       dst_logic_port,
                                                       bidi=True)
            except Exception:
                is_connected = False

            if not is_connected:
                mapping_actions.disconnect({(src_logic_port, dst_logic_port)},
                                           bidi=True)
                raise ConnectionPortsError(
                    'Cannot connect port {} to port {} during {}sec'.format(
                        src_logic_port.original_logical_name,
                        dst_logic_port.original_logical_name,
                        self._mapping_timeout,
                    ))