use metering api def from neutron-lib
The metering extension's API definition was rehomed into neutron-lib with commit I1b3285287be2429f7cf9913a7e6204db26371ced. This patch consumes the API definition removing the rehomed code from neutron and updating references to use lib's code. NeutronLibImpact Change-Id: Iacd69a3b332ee494946befc2f35638410e27cfb9
This commit is contained in:
parent
271a0d9f72
commit
c6ed3bf819
neutron
db/metering
extensions
services/metering
tests
tempest/api
unit
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
import netaddr
|
||||
from neutron_lib.exceptions import metering as metering_exc
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
@ -59,14 +60,14 @@ class MeteringDbMixin(metering.MeteringPluginBase,
|
||||
metering_label = metering_objs.MeteringLabel.get_object(context,
|
||||
id=label_id)
|
||||
if not metering_label:
|
||||
raise metering.MeteringLabelNotFound(label_id=label_id)
|
||||
raise metering_exc.MeteringLabelNotFound(label_id=label_id)
|
||||
return metering_label
|
||||
|
||||
def delete_metering_label(self, context, label_id):
|
||||
deleted = metering_objs.MeteringLabel.delete_objects(
|
||||
context, id=label_id)
|
||||
if not deleted:
|
||||
raise metering.MeteringLabelNotFound(label_id=label_id)
|
||||
raise metering_exc.MeteringLabelNotFound(label_id=label_id)
|
||||
|
||||
def get_metering_label(self, context, label_id, fields=None):
|
||||
return self._make_metering_label_dict(
|
||||
@ -105,7 +106,7 @@ class MeteringDbMixin(metering.MeteringPluginBase,
|
||||
metering_label_rule = metering_objs.MeteringLabelRule.get_object(
|
||||
context, id=rule_id)
|
||||
if not metering_label_rule:
|
||||
raise metering.MeteringLabelRuleNotFound(rule_id=rule_id)
|
||||
raise metering_exc.MeteringLabelRuleNotFound(rule_id=rule_id)
|
||||
return metering_label_rule
|
||||
|
||||
def get_metering_label_rule(self, context, rule_id, fields=None):
|
||||
@ -126,7 +127,7 @@ class MeteringDbMixin(metering.MeteringPluginBase,
|
||||
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.MeteringLabelRuleOverlaps(
|
||||
raise metering_exc.MeteringLabelRuleOverlaps(
|
||||
remote_ip_prefix=remote_ip_prefix)
|
||||
|
||||
def create_metering_label_rule(self, context, metering_label_rule):
|
||||
@ -147,7 +148,7 @@ class MeteringDbMixin(metering.MeteringPluginBase,
|
||||
remote_ip_prefix=netaddr.IPNetwork(ip_prefix))
|
||||
rule.create()
|
||||
except db_exc.DBReferenceError:
|
||||
raise metering.MeteringLabelNotFound(label_id=label_id)
|
||||
raise metering_exc.MeteringLabelNotFound(label_id=label_id)
|
||||
|
||||
return self._make_metering_label_rule_dict(rule)
|
||||
|
||||
|
@ -14,99 +14,17 @@
|
||||
|
||||
import abc
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import metering as metering_apidef
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib.db import constants as db_const
|
||||
from neutron_lib import exceptions as nexception
|
||||
from neutron_lib.plugins import constants
|
||||
from neutron_lib.services import base as service_base
|
||||
import six
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.api.v2 import resource_helper
|
||||
|
||||
|
||||
class MeteringLabelNotFound(nexception.NotFound):
|
||||
message = _("Metering label %(label_id)s does not exist")
|
||||
|
||||
|
||||
class DuplicateMeteringRuleInPost(nexception.InUse):
|
||||
message = _("Duplicate Metering Rule in POST.")
|
||||
|
||||
|
||||
class MeteringLabelRuleNotFound(nexception.NotFound):
|
||||
message = _("Metering label rule %(rule_id)s does not exist")
|
||||
|
||||
|
||||
class MeteringLabelRuleOverlaps(nexception.Conflict):
|
||||
message = _("Metering label rule with remote_ip_prefix "
|
||||
"%(remote_ip_prefix)s overlaps another")
|
||||
|
||||
|
||||
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}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Metering(extensions.ExtensionDescriptor):
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "Neutron Metering"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "metering"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "Neutron Metering extension."
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2013-06-12T10:00:00-00:00"
|
||||
class Metering(extensions.APIExtensionDescriptor):
|
||||
api_definition = metering_apidef
|
||||
|
||||
@classmethod
|
||||
def get_plugin_interface(cls):
|
||||
@ -116,24 +34,12 @@ class Metering(extensions.ExtensionDescriptor):
|
||||
def get_resources(cls):
|
||||
"""Returns Ext Resources."""
|
||||
plural_mappings = resource_helper.build_plural_mappings(
|
||||
{}, RESOURCE_ATTRIBUTE_MAP)
|
||||
{}, metering_apidef.RESOURCE_ATTRIBUTE_MAP)
|
||||
# PCM: Metering sets pagination and sorting to True. Do we have cfg
|
||||
# entries for these so can be read? Else, must pass in.
|
||||
return resource_helper.build_resource_info(plural_mappings,
|
||||
RESOURCE_ATTRIBUTE_MAP,
|
||||
constants.METERING,
|
||||
translate_name=True,
|
||||
allow_bulk=True)
|
||||
|
||||
def update_attributes_map(self, attributes):
|
||||
super(Metering, self).update_attributes_map(
|
||||
attributes, extension_attrs_map=RESOURCE_ATTRIBUTE_MAP)
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return RESOURCE_ATTRIBUTE_MAP
|
||||
else:
|
||||
return {}
|
||||
return resource_helper.build_resource_info(
|
||||
plural_mappings, metering_apidef.RESOURCE_ATTRIBUTE_MAP,
|
||||
constants.METERING, translate_name=True, allow_bulk=True)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import metering as metering_apidef
|
||||
|
||||
from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api
|
||||
from neutron.common import rpc as n_rpc
|
||||
from neutron.common import topics
|
||||
@ -22,7 +24,7 @@ from neutron import service
|
||||
|
||||
class MeteringPlugin(metering_db.MeteringDbMixin):
|
||||
"""Implementation of the Neutron Metering Service Plugin."""
|
||||
supported_extension_aliases = ["metering"]
|
||||
supported_extension_aliases = [metering_apidef.ALIAS]
|
||||
path_prefix = "/metering"
|
||||
|
||||
def __init__(self):
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import metering as metering_apidef
|
||||
from neutron_lib.db import constants as db_const
|
||||
from tempest.lib.common.utils import data_utils
|
||||
from tempest.lib import decorators
|
||||
@ -31,7 +32,7 @@ class MeteringTestJSON(base.BaseAdminNetworkTest):
|
||||
List, Show, Create, Delete Metering labels rules
|
||||
"""
|
||||
|
||||
required_extensions = ['metering']
|
||||
required_extensions = [metering_apidef.ALIAS]
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import metering as metering_apidef
|
||||
from neutron_lib.db import constants as db_const
|
||||
from tempest.lib import decorators
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
@ -23,7 +24,7 @@ LONG_NAME_NG = 'x' * (db_const.NAME_FIELD_SIZE + 1)
|
||||
|
||||
class MeteringNegativeTestJSON(base.BaseAdminNetworkTest):
|
||||
|
||||
required_extensions = ['metering']
|
||||
required_extensions = [metering_apidef.ALIAS]
|
||||
|
||||
@decorators.attr(type='negative')
|
||||
@decorators.idempotent_id('8b3f7c84-9d37-4771-8681-bfd2c07f3c2d')
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
import contextlib
|
||||
|
||||
from neutron_lib.api.definitions import metering as metering_apidef
|
||||
from neutron_lib import constants as n_consts
|
||||
from neutron_lib import context
|
||||
from neutron_lib.db import constants as db_const
|
||||
@ -24,7 +25,6 @@ import webob.exc
|
||||
from neutron.api import extensions
|
||||
from neutron.common import config
|
||||
import neutron.extensions
|
||||
from neutron.extensions import metering
|
||||
from neutron.services.metering import metering_plugin
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2
|
||||
|
||||
@ -120,7 +120,7 @@ class MeteringPluginDbTestCase(
|
||||
|
||||
resource_prefix_map = dict(
|
||||
(k.replace('_', '-'), "/metering")
|
||||
for k in metering.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
)
|
||||
|
||||
def setUp(self, plugin=None):
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from neutron_lib.api.definitions import metering as metering_apidef
|
||||
from neutron_lib import context
|
||||
from neutron_lib.plugins import constants
|
||||
from neutron_lib.plugins import directory
|
||||
@ -75,7 +76,7 @@ class TestMeteringPlugin(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
|
||||
|
||||
resource_prefix_map = dict(
|
||||
(k.replace('_', '-'), "/metering")
|
||||
for k in ext_metering.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
@ -319,7 +320,7 @@ class TestMeteringPluginL3AgentScheduler(
|
||||
|
||||
resource_prefix_map = dict(
|
||||
(k.replace('_', '-'), "/metering")
|
||||
for k in ext_metering.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
)
|
||||
|
||||
def setUp(self, plugin_str=None, service_plugins=None, scheduler=None):
|
||||
@ -444,7 +445,7 @@ class TestMeteringPluginRpcFromL3Agent(
|
||||
|
||||
resource_prefix_map = dict(
|
||||
(k.replace('_', '-'), "/metering")
|
||||
for k in ext_metering.RESOURCE_ATTRIBUTE_MAP
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user