From 9423b33369e35d98b92669b576b310401b83595e Mon Sep 17 00:00:00 2001 From: Boden R Date: Wed, 16 Aug 2017 13:26:33 -0600 Subject: [PATCH] rehome metering extension api definition This patch rehomes the metering extension's API definition and exceptions into neutron-lib. UTs and a release note are also included. Change-Id: I1b3285287be2429f7cf9913a7e6204db26371ced --- neutron_lib/api/definitions/__init__.py | 2 + neutron_lib/api/definitions/metering.py | 98 +++++++++++++++++++ neutron_lib/exceptions/metering.py | 33 +++++++ .../unit/api/definitions/test_metering.py | 24 +++++ ...home-metering-apidef-d9a0e70cbecc2bcc.yaml | 6 ++ 5 files changed, 163 insertions(+) create mode 100644 neutron_lib/api/definitions/metering.py create mode 100644 neutron_lib/exceptions/metering.py create mode 100644 neutron_lib/tests/unit/api/definitions/test_metering.py create mode 100644 releasenotes/notes/rehome-metering-apidef-d9a0e70cbecc2bcc.yaml diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 9e1463e43..7f7229342 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -27,6 +27,7 @@ from neutron_lib.api.definitions import firewallrouterinsertion from neutron_lib.api.definitions import l3 from neutron_lib.api.definitions import logging from neutron_lib.api.definitions import logging_resource +from neutron_lib.api.definitions import metering from neutron_lib.api.definitions import network from neutron_lib.api.definitions import network_mtu from neutron_lib.api.definitions import port @@ -58,6 +59,7 @@ _ALL_API_DEFINITIONS = { l3, logging, logging_resource, + metering, network, network_mtu, port, diff --git a/neutron_lib/api/definitions/metering.py b/neutron_lib/api/definitions/metering.py new file mode 100644 index 000000000..511f4ac50 --- /dev/null +++ b/neutron_lib/api/definitions/metering.py @@ -0,0 +1,98 @@ +# Copyright (C) 2013 eNovance SAS +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api import converters +from neutron_lib.db import constants as db_const + + +METERING_LABELS = 'metering_labels' +METERING_LABEL_RULES = 'metering_label_rules' + +ALIAS = 'metering' +IS_SHIM_EXTENSION = False +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'Neutron Metering' +API_PREFIX = '' +DESCRIPTION = 'Neutron Metering extension.' +UPDATED_TIMESTAMP = '2013-06-12T10:00:00-00:00' +RESOURCE_ATTRIBUTE_MAP = { + METERING_LABELS: { + 'id': { + 'allow_post': False, 'allow_put': False, + 'is_visible': True, + 'primary_key': True + }, + 'name': { + 'allow_post': True, 'allow_put': False, + 'validate': {'type:string': db_const.NAME_FIELD_SIZE}, + 'is_visible': True, 'default': '' + }, + 'description': { + 'allow_post': True, 'allow_put': False, + 'validate': { + 'type:string': db_const.LONG_DESCRIPTION_FIELD_SIZE}, + 'is_visible': True, 'default': '' + }, + 'tenant_id': { + 'allow_post': True, 'allow_put': False, + 'required_by_policy': True, + 'validate': { + 'type:string': db_const.PROJECT_ID_FIELD_SIZE}, + 'is_visible': True + }, + 'shared': { + 'allow_post': True, 'allow_put': False, + 'is_visible': True, 'default': False, + 'convert_to': converters.convert_to_boolean + } + }, + METERING_LABEL_RULES: { + 'id': { + 'allow_post': False, 'allow_put': False, + 'is_visible': True, + 'primary_key': True + }, + 'metering_label_id': { + 'allow_post': True, 'allow_put': False, + 'validate': {'type:uuid': None}, + 'is_visible': True, 'required_by_policy': True + }, + 'direction': { + 'allow_post': True, 'allow_put': False, + 'is_visible': True, + 'validate': {'type:values': ['ingress', 'egress']} + }, + 'excluded': { + 'allow_post': True, 'allow_put': False, + 'is_visible': True, 'default': False, + 'convert_to': converters.convert_to_boolean + }, + 'remote_ip_prefix': { + 'allow_post': True, 'allow_put': False, + 'is_visible': True, 'required_by_policy': True, + 'validate': {'type:subnet': None} + }, + 'tenant_id': { + 'allow_post': True, 'allow_put': False, + 'required_by_policy': True, + 'validate': {'type:string': db_const.PROJECT_ID_FIELD_SIZE}, + 'is_visible': True + } + } +} +SUB_RESOURCE_ATTRIBUTE_MAP = {} +ACTION_MAP = {} +REQUIRED_EXTENSIONS = [] +OPTIONAL_EXTENSIONS = [] +ACTION_STATUS = {} diff --git a/neutron_lib/exceptions/metering.py b/neutron_lib/exceptions/metering.py new file mode 100644 index 000000000..f6e6e057f --- /dev/null +++ b/neutron_lib/exceptions/metering.py @@ -0,0 +1,33 @@ +# Copyright (C) 2013 eNovance SAS +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib._i18n import _ +from neutron_lib import exceptions + + +class MeteringLabelNotFound(exceptions.NotFound): + message = _("Metering label '%(label_id)s' does not exist.") + + +class DuplicateMeteringRuleInPost(exceptions.InUse): + message = _("Duplicate Metering Rule in POST.") + + +class MeteringLabelRuleNotFound(exceptions.NotFound): + message = _("Metering label rule '%(rule_id)s' does not exist.") + + +class MeteringLabelRuleOverlaps(exceptions.Conflict): + message = _("Metering label rule with remote_ip_prefix " + "'%(remote_ip_prefix)s' overlaps another.") diff --git a/neutron_lib/tests/unit/api/definitions/test_metering.py b/neutron_lib/tests/unit/api/definitions/test_metering.py new file mode 100644 index 000000000..93f488d5e --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_metering.py @@ -0,0 +1,24 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import metering +from neutron_lib.tests.unit.api.definitions import base + + +class MeteringDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = metering + extension_resources = (metering.METERING_LABEL_RULES, + metering.METERING_LABELS) + extension_attributes = ('remote_ip_prefix', + 'excluded', + 'metering_label_id', + 'direction') diff --git a/releasenotes/notes/rehome-metering-apidef-d9a0e70cbecc2bcc.yaml b/releasenotes/notes/rehome-metering-apidef-d9a0e70cbecc2bcc.yaml new file mode 100644 index 000000000..1be45eebf --- /dev/null +++ b/releasenotes/notes/rehome-metering-apidef-d9a0e70cbecc2bcc.yaml @@ -0,0 +1,6 @@ +--- +features: + - The ``metering`` extension's API is now available in + ``neutron_lib.api.definitions.metering``. + - Exceptions for the ``metering`` extension are available in + ``neutron_lib.exceptions.metering``.