@ -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 )