Exemple #1
0
    def create_metering_label_rule(self, context, metering_label_rule):
        label_id = metering_label_rule['metering_label_id']

        try:
            with db_api.CONTEXT_WRITER.using(context):
                rule = metering_objs.MeteringLabelRule(
                    context,
                    id=uuidutils.generate_uuid(),
                    metering_label_id=label_id,
                    direction=metering_label_rule['direction'],
                    excluded=metering_label_rule['excluded'],
                )
                if metering_label_rule.get('remote_ip_prefix'):
                    rule.remote_ip_prefix = netaddr.IPNetwork(
                        metering_label_rule['remote_ip_prefix'])

                if metering_label_rule.get('source_ip_prefix'):
                    rule.source_ip_prefix = netaddr.IPNetwork(
                        metering_label_rule['source_ip_prefix'])

                if metering_label_rule.get('destination_ip_prefix'):
                    rule.destination_ip_prefix = netaddr.IPNetwork(
                        metering_label_rule['destination_ip_prefix'])
                rule.create()
                return self._make_metering_label_rule_dict(rule)
        except db_exc.DBReferenceError:
            raise metering_exc.MeteringLabelNotFound(label_id=label_id)
Exemple #2
0
    def create_metering_label_rule(self, context, metering_label_rule):
        m = metering_label_rule['metering_label_rule']
        try:
            with db_api.context_manager.writer.using(context):
                label_id = m['metering_label_id']
                ip_prefix = m['remote_ip_prefix']
                direction = m['direction']
                excluded = m['excluded']

                self._validate_cidr(context, label_id, ip_prefix, direction,
                                    excluded)
                rule = metering_objs.MeteringLabelRule(
                    context,
                    id=uuidutils.generate_uuid(),
                    metering_label_id=label_id,
                    direction=direction,
                    excluded=m['excluded'],
                    remote_ip_prefix=netaddr.IPNetwork(ip_prefix))
                rule.create()
        except db_exc.DBReferenceError:
            raise metering_exc.MeteringLabelNotFound(label_id=label_id)

        return self._make_metering_label_rule_dict(rule)