Esempio n. 1
0
def filter_calculate_neighbor_ip_mask_31(value):
    """
    Function to calculate a neighbors IP using a 31 bit mask
    :param value:
    :return: An error, or a IP address
    """
    error = f'{value} !!!! possible error should be a valid ipv4 address!!!!'
    if not value:  # pylint: disable=no-else-return
        J2_FILTER_LOGGER.info('filter_calculate_neighbor_ip_mask_31 %s', error)
        return error

    else:
        try:
            if ipv4.ip(value, return_tuple=False):  # pylint: disable=no-else-return
                this_ip, nei_ip = ipv4.get_neighbor_ip(value, '31')  # pylint: disable=unused-variable
                return nei_ip

            else:
                J2_FILTER_LOGGER.info(
                    'filter_calculate_neighbor_ip_mask_31 %s', error)
                return error

        except ValueError as e:  # pylint: disable=invalid-name
            J2_FILTER_LOGGER.info(
                'filter_calculate_neighbor_ip_mask_31 %s, caught %s', error, e)
            return error
Esempio n. 2
0
def filter_calculate_neighbor_ip_mask_31(value):
    """
    Function to calculate a neighbors IP using a 31 bit mask
    :param value:
    :return: An error, or a IP address
    """
    error = '{value} !!!! possible error should be a valid ipv4 address!!!!'.format(
        value=value)
    if not value:
        J2_FILTER_LOGGER.info(
            'filter_calculate_neighbor_ip_mask_31 {}'.format(error))
        return error

    else:
        try:
            if ipv4.ip(value, return_tuple=False):
                this_ip, nei_ip = ipv4.get_neighbor_ip(value, '31')
                return nei_ip

            else:
                J2_FILTER_LOGGER.info(
                    'filter_calculate_neighbor_ip_mask_31 {}'.format(error))
                return error

        except ValueError as e:
            J2_FILTER_LOGGER.info(
                'filter_calculate_neighbor_ip_mask_31 {}, caught {}'.format(
                    error, e))
            return error
    def set_lines(self, line_data):
        temp_dict = dict()
        prev_enum = 0
        hit_once = False
        line_data_split = line_data.split()
        for enum, entry in enumerate(line_data_split):
            if ipv4.ip(entry, return_tuple=False):
                if not hit_once:
                    temp_network = None

                else:
                    temp_network = None

            elif ipv4.ip_mask(entry, return_tuple=False):
                if not hit_once:
                    temp_dict.update({'source_network': entry})
                    hit_once = True
                else:
                    temp_dict.update({'destination_network': entry})
                    print(temp_dict)

        if line_data_split[2] == 'ip':
            if ipv4.ip_mask(line_data_split[3], return_tuple=False):
                temp_dict.update({'sequence': line_data_split[0],
                                  'permit_deny': line_data_split[1],
                                  'protocol': line_data_split[2]})

            else:
                temp_dict.update({'sequence': line_data_split[0],
                                  'permit_deny': line_data_split[1],
                                  'protocol': line_data_split[2],
                                  'source_network': ' '.join(line_data_split[3:5]),
                                  'destination_network': ' '.join(line_data_split[5:7])})

            self.lines.append(temp_dict)

        elif line_data_split[2] != 'ip':
            if 'eq' or 'range' in line_data:
                if line_data.count('eq') == 2:
                    pass
                elif line_data.count('eq') == 1:
                    pass
                elif line_data.count('range') == 2:
                    pass
                elif line_data.count('range') == 1:
                    pass

            else:
                self.lines.append({'sequence': line_data_split[0],
                                   'permit_deny': line_data_split[1],
                                   'protocol': line_data_split[2],
                                   'source_network': ' '.join(line_data_split[3:5]),
                                   'destination_network': ' '.join(line_data_split[5:7])})

        else:
            self.lines.append({'sequence': line_data_split[0],
                               'permit_deny': line_data_split[1],
                               'protocol': line_data_split[2]})
Esempio n. 4
0
    def set_lines(self, line_data):  # pylint: disable=too-many-branches
        """Method to clean a line of ACL data

        :type line_data: String
        :param line_data: The ACL line
        """
        temp_dict = dict()
        # TODO: Need to check this variable if needed
        prev_enum = 0  # pylint: disable=unused-variable
        hit_once = False
        line_data_split = line_data.split()  # pylint: disable=unused-variable
        for enum, entry in enumerate(line_data_split):  # pylint: disable=unused-variable
            if ipv4.ip(entry, return_tuple=False):
                if not hit_once:  # pylint: disable=unused-variable
                    # TODO: Need to check this variable if needed
                    temp_network = None  # pylint: disable=unused-variable

                else:
                    # TODO: Need to check this variable if needed
                    temp_network = None  # pylint: disable=unused-variable

            elif ipv4.ip_mask(entry, return_tuple=False):
                if not hit_once:
                    temp_dict.update({'source_network': entry})
                    hit_once = True
                else:
                    temp_dict.update({'destination_network': entry})
                    print(temp_dict)

        if line_data_split[2] == 'ip':
            if ipv4.ip_mask(line_data_split[3], return_tuple=False):
                temp_dict.update({
                    'sequence': line_data_split[0],
                    'permit_deny': line_data_split[1],
                    'protocol': line_data_split[2]
                })

            else:
                temp_dict.update({
                    'sequence':
                    line_data_split[0],
                    'permit_deny':
                    line_data_split[1],
                    'protocol':
                    line_data_split[2],
                    'source_network':
                    ' '.join(line_data_split[3:5]),
                    'destination_network':
                    ' '.join(line_data_split[5:7])
                })

            self.lines.append(temp_dict)

        elif line_data_split[2] != 'ip':
            # TODO: Need to check on this
            if 'eq' or 'range' in line_data:  # pylint: disable=condition-evals-to-constant
                if line_data.count('eq') == 2:
                    pass
                elif line_data.count('eq') == 1:
                    pass
                elif line_data.count('range') == 2:
                    pass
                elif line_data.count('range') == 1:
                    pass

            else:
                self.lines.append({
                    'sequence':
                    line_data_split[0],
                    'permit_deny':
                    line_data_split[1],
                    'protocol':
                    line_data_split[2],
                    'source_network':
                    ' '.join(line_data_split[3:5]),
                    'destination_network':
                    ' '.join(line_data_split[5:7])
                })

        else:
            self.lines.append({
                'sequence': line_data_split[0],
                'permit_deny': line_data_split[1],
                'protocol': line_data_split[2]
            })