Exemplo n.º 1
0
    def verify_rule_overlap(db_metering_rule, metering_label_rule,
                            attribute_name):
        if db_metering_rule.get(attribute_name) and metering_label_rule.get(
                attribute_name):
            remote_ip_prefix = metering_label_rule[attribute_name]
            cidr = [db_metering_rule.get(attribute_name)]
            new_cidr_ipset = netaddr.IPSet([remote_ip_prefix])

            if netaddr.IPSet(cidr) & new_cidr_ipset:
                LOG.warning(
                    "The metering rule [%s] overlaps with"
                    " previously created rule [%s]. It is not an"
                    " expected use case, and people should use"
                    " it wisely.", metering_label_rule, db_metering_rule)
                raise metering_exc.MeteringLabelRuleOverlaps(
                    remote_ip_prefix=remote_ip_prefix)
Exemplo n.º 2
0
    def _validate_cidr(self, context, label_id, remote_ip_prefix, direction,
                       excluded):
        r_ips = self.get_metering_label_rules(context,
                                              filters={
                                                  'metering_label_id':
                                                  [label_id],
                                                  'direction': [direction],
                                                  'excluded': [excluded]
                                              },
                                              fields=['remote_ip_prefix'])

        cidrs = [r['remote_ip_prefix'] for r in r_ips]
        new_cidr_ipset = netaddr.IPSet([remote_ip_prefix])
        if (netaddr.IPSet(cidrs) & new_cidr_ipset):
            raise metering_exc.MeteringLabelRuleOverlaps(
                remote_ip_prefix=remote_ip_prefix)