@property
    def filtered(self):
        filters = self.switch.machine_filters
        port = self.port
        unmatched_allowed = True
        ports_pattern = re.compile(r'(\D*)(\d+)-(\d+)(\D*)')
        port_pattern = re.compile(r'(\D*)(\d+)(\D*)')
        port_match = port_pattern.match(port)
        if port_match:
            port_prefix = port_match.group(1)
            port_number = int(port_match.group(2))
            port_suffix = port_match.group(3)
        else:
            port_prefix = ''
            port_number = 0
            port_suffix = ''
        for port_filter in filters:
            filter_type = port_filter.get('filter_type', 'allow')
            denied = filter_type != 'allow'
            unmatched_allowed = denied
            if 'ports' in port_filter:
                if 'all' in port_filter['ports']:
                    return denied
                if port in port_filter['ports']:
                    return denied
                if port_match:
                    for port_or_ports in port_filter['ports']:
                        ports_match = ports_pattern.match(port_or_ports)
                        if ports_match:
                            filter_port_prefix = ports_match.group(1)
                            filter_port_start = int(ports_match.group(2))
                            filter_port_end = int(ports_match.group(3))
                            filter_port_suffix = ports_match.group(4)
                            if (
                                filter_port_prefix == port_prefix and
                                filter_port_suffix == port_suffix and
                                filter_port_start <= port_number and
                                port_number <= filter_port_end
                            ):
                                return denied
            else:
                filter_port_prefix = port_filter.get('port_prefix', '')
                filter_port_suffix = port_filter.get('port_suffix', '')
                if (
                    port_match and
                    port_prefix == filter_port_prefix and
                    port_suffix == filter_port_suffix
                ):
                    if (
                        'port_start' not in port_filter or
                        port_number >= port_filter['port_start']
                    ) and (
                        'port_end' not in port_filter or
                        port_number <= port_filter['port_end']
                    ):
                        return denied
        return not unmatched_allowed
Check if switch machine should be filtered.
dataset/ETHPy150Open openstack/compass-core/compass/db/models.py/SwitchMachine.filtered