Refactoring config options for quota

Refactoring Neutron configuration options for quota to be in
neutron/conf. This will allow centralization of all configuration
options and provide an easy way to import.
It is similar to the Nova implementation found here:
http://specs.openstack.org/openstack/nova-specs/specs/mitaka/implemented/centralize-config-options.html

Partial-Bug: #1563069

Change-Id: I7723ba9b24dd5cf74b321bd0fc54df0666594bbc
This commit is contained in:
Aradhana Singh 2016-04-19 22:03:27 +00:00 committed by Dariusz Smigiel
parent 60db12f9d2
commit 97372a1431
8 changed files with 117 additions and 82 deletions

0
neutron/conf/__init__.py Normal file
View File

97
neutron/conf/quota.py Normal file
View File

@ -0,0 +1,97 @@
# Copyright 2016 Intel Corporation.
# All Rights Reserved.
#
# 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 oslo_config import cfg
from neutron._i18n import _
QUOTA_DB_MODULE = 'neutron.db.quota.driver'
QUOTA_DB_DRIVER = '%s.DbQuotaDriver' % QUOTA_DB_MODULE
QUOTA_CONF_DRIVER = 'neutron.quota.ConfDriver'
default_quota_items = ['network', 'subnet', 'port']
QUOTAS_CFG_GROUP = 'QUOTAS'
# quota_opts from neutron/quota/__init__.py
# renamed quota_opts to core_quota_opts
core_quota_opts = [
cfg.ListOpt('quota_items',
default=default_quota_items,
deprecated_for_removal=True,
help=_('Resource name(s) that are supported in quota '
'features. This option is now deprecated for '
'removal.')),
cfg.IntOpt('default_quota',
default=-1,
help=_('Default number of resource allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_network',
default=10,
help=_('Number of networks allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_subnet',
default=10,
help=_('Number of subnets allowed per tenant, '
'A negative value means unlimited.')),
cfg.IntOpt('quota_port',
default=50,
help=_('Number of ports allowed per tenant. '
'A negative value means unlimited.')),
cfg.StrOpt('quota_driver',
default=QUOTA_DB_DRIVER,
help=_('Default driver to use for quota checks.')),
cfg.BoolOpt('track_quota_usage',
default=True,
help=_('Keep in track in the database of current resource '
'quota usage. Plugins which do not leverage the '
'neutron database should set this flag to False.')),
]
# security_group_quota_opts from neutron/extensions/securitygroup.py
security_group_quota_opts = [
cfg.IntOpt('quota_security_group',
default=10,
help=_('Number of security groups allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_security_group_rule',
default=100,
help=_('Number of security rules allowed per tenant. '
'A negative value means unlimited.')),
]
# l3_quota_opts from neutron/extensions/l3.py
l3_quota_opts = [
cfg.IntOpt('quota_router',
default=10,
help=_('Number of routers allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_floatingip',
default=50,
help=_('Number of floating IPs allowed per tenant. '
'A negative value means unlimited.')),
]
# rbac_quota_opts from neutron/extensions/rbac.py
rbac_quota_opts = [
cfg.IntOpt('quota_rbac_policy', default=10,
deprecated_name='quota_rbac_entry',
help=_('Default number of RBAC entries allowed per tenant. '
'A negative value means unlimited.'))
]
def register_quota_opts(opts, cfg=cfg.CONF):
cfg.register_opts(opts, QUOTAS_CFG_GROUP)

View File

@ -86,13 +86,6 @@ _core_opts = [
help=_("Enforce using split branches file structure.")) help=_("Enforce using split branches file structure."))
] ]
_quota_opts = [
cfg.StrOpt('quota_driver',
default='',
help=_('Neutron quota driver class'),
deprecated_for_removal=True),
]
_db_opts = [ _db_opts = [
cfg.StrOpt('connection', cfg.StrOpt('connection',
deprecated_name='sql_connection', deprecated_name='sql_connection',
@ -108,7 +101,6 @@ _db_opts = [
CONF = cfg.ConfigOpts() CONF = cfg.ConfigOpts()
CONF.register_cli_opts(_core_opts) CONF.register_cli_opts(_core_opts)
CONF.register_cli_opts(_db_opts, 'database') CONF.register_cli_opts(_db_opts, 'database')
CONF.register_opts(_quota_opts, 'QUOTAS')
def do_alembic_command(config, cmd, revision=None, desc=None, **kwargs): def do_alembic_command(config, cmd, revision=None, desc=None, **kwargs):

View File

@ -17,13 +17,13 @@ import abc
from neutron_lib.api import converters from neutron_lib.api import converters
from neutron_lib import exceptions as nexception from neutron_lib import exceptions as nexception
from oslo_config import cfg
import six import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
from neutron.api.v2 import resource_helper from neutron.api.v2 import resource_helper
from neutron.conf import quota
from neutron.pecan_wsgi import controllers from neutron.pecan_wsgi import controllers
from neutron.plugins.common import constants from neutron.plugins.common import constants
@ -156,17 +156,8 @@ RESOURCE_ATTRIBUTE_MAP = {
}, },
} }
l3_quota_opts = [ # Register the configuration options
cfg.IntOpt('quota_router', quota.register_quota_opts(quota.l3_quota_opts)
default=10,
help=_('Number of routers allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_floatingip',
default=50,
help=_('Number of floating IPs allowed per tenant. '
'A negative value means unlimited.')),
]
cfg.CONF.register_opts(l3_quota_opts, 'QUOTAS')
class L3(extensions.ExtensionDescriptor): class L3(extensions.ExtensionDescriptor):

View File

@ -14,12 +14,12 @@
# under the License. # under the License.
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from neutron._i18n import _ from neutron._i18n import _
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
from neutron.api.v2 import base from neutron.api.v2 import base
from neutron.conf import quota
from neutron.db import rbac_db_models from neutron.db import rbac_db_models
from neutron import manager from neutron import manager
from neutron.quota import resource_registry from neutron.quota import resource_registry
@ -78,13 +78,8 @@ RESOURCE_ATTRIBUTE_MAP = {
} }
} }
rbac_quota_opts = [ # Register the configuration options
cfg.IntOpt('quota_rbac_policy', default=10, quota.register_quota_opts(quota.rbac_quota_opts)
deprecated_name='quota_rbac_entry',
help=_('Default number of RBAC entries allowed per tenant. '
'A negative value means unlimited.'))
]
cfg.CONF.register_opts(rbac_quota_opts, 'QUOTAS')
class Rbac(extensions.ExtensionDescriptor): class Rbac(extensions.ExtensionDescriptor):

View File

@ -19,7 +19,6 @@ import netaddr
from neutron_lib.api import validators from neutron_lib.api import validators
from neutron_lib import constants as const from neutron_lib import constants as const
from neutron_lib import exceptions as nexception from neutron_lib import exceptions as nexception
from oslo_config import cfg
from oslo_utils import uuidutils from oslo_utils import uuidutils
import six import six
@ -29,6 +28,7 @@ from neutron.api.v2 import attributes as attr
from neutron.api.v2 import base from neutron.api.v2 import base
from neutron.common import constants as n_const from neutron.common import constants as n_const
from neutron.common import exceptions from neutron.common import exceptions
from neutron.conf import quota
from neutron import manager from neutron import manager
from neutron.quota import resource_registry from neutron.quota import resource_registry
@ -286,17 +286,9 @@ EXTENDED_ATTRIBUTES_2_0 = {
'is_visible': True, 'is_visible': True,
'convert_to': convert_to_uuid_list_or_none, 'convert_to': convert_to_uuid_list_or_none,
'default': const.ATTR_NOT_SPECIFIED}}} 'default': const.ATTR_NOT_SPECIFIED}}}
security_group_quota_opts = [
cfg.IntOpt('quota_security_group', # Register the configuration options
default=10, quota.register_quota_opts(quota.security_group_quota_opts)
help=_('Number of security groups allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_security_group_rule',
default=100,
help=_('Number of security rules allowed per tenant. '
'A negative value means unlimited.')),
]
cfg.CONF.register_opts(security_group_quota_opts, 'QUOTAS')
class Securitygroup(extensions.ExtensionDescriptor): class Securitygroup(extensions.ExtensionDescriptor):

View File

@ -29,6 +29,7 @@ import neutron.agent.linux.ra
import neutron.agent.metadata.config import neutron.agent.metadata.config
import neutron.agent.ovsdb.api import neutron.agent.ovsdb.api
import neutron.agent.securitygroups_rpc import neutron.agent.securitygroups_rpc
import neutron.conf.quota
import neutron.db.agents_db import neutron.db.agents_db
import neutron.db.agentschedulers_db import neutron.db.agentschedulers_db
import neutron.db.dvr_mac_db import neutron.db.dvr_mac_db
@ -54,7 +55,6 @@ import neutron.plugins.ml2.drivers.type_geneve
import neutron.plugins.ml2.drivers.type_gre import neutron.plugins.ml2.drivers.type_gre
import neutron.plugins.ml2.drivers.type_vlan import neutron.plugins.ml2.drivers.type_vlan
import neutron.plugins.ml2.drivers.type_vxlan import neutron.plugins.ml2.drivers.type_vxlan
import neutron.quota
import neutron.service import neutron.service
import neutron.services.metering.agents.metering_agent import neutron.services.metering.agents.metering_agent
import neutron.services.qos.notification_drivers.manager import neutron.services.qos.notification_drivers.manager
@ -101,8 +101,8 @@ def list_extension_opts():
neutron.extensions.allowedaddresspairs.allowed_address_pair_opts), neutron.extensions.allowedaddresspairs.allowed_address_pair_opts),
('quotas', ('quotas',
itertools.chain( itertools.chain(
neutron.extensions.l3.l3_quota_opts, neutron.conf.quota.l3_quota_opts,
neutron.extensions.securitygroup.security_group_quota_opts) neutron.conf.quota.security_group_quota_opts)
) )
] ]
@ -138,7 +138,7 @@ def list_opts():
itertools.chain( itertools.chain(
neutron.common.config.nova_opts) neutron.common.config.nova_opts)
), ),
('quotas', neutron.quota.quota_opts) ('quotas', neutron.conf.quota.core_quota_opts)
] ]

View File

@ -26,51 +26,19 @@ import webob
from neutron._i18n import _, _LI, _LW from neutron._i18n import _, _LI, _LW
from neutron.common import exceptions from neutron.common import exceptions
from neutron.conf import quota
from neutron.db.quota import api as quota_api from neutron.db.quota import api as quota_api
from neutron.quota import resource_registry from neutron.quota import resource_registry
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
QUOTA_DB_MODULE = 'neutron.db.quota.driver' QUOTA_DB_MODULE = quota.QUOTA_DB_MODULE
QUOTA_DB_DRIVER = '%s.DbQuotaDriver' % QUOTA_DB_MODULE QUOTA_DB_DRIVER = quota.QUOTA_DB_DRIVER
QUOTA_CONF_DRIVER = 'neutron.quota.ConfDriver' QUOTA_CONF_DRIVER = quota.QUOTA_CONF_DRIVER
default_quota_items = ['network', 'subnet', 'port'] default_quota_items = quota.default_quota_items
quota_opts = [
cfg.ListOpt('quota_items',
default=default_quota_items,
deprecated_for_removal=True,
help=_('Resource name(s) that are supported in quota '
'features. This option is now deprecated for '
'removal.')),
cfg.IntOpt('default_quota',
default=-1,
help=_('Default number of resource allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_network',
default=10,
help=_('Number of networks allowed per tenant. '
'A negative value means unlimited.')),
cfg.IntOpt('quota_subnet',
default=10,
help=_('Number of subnets allowed per tenant, '
'A negative value means unlimited.')),
cfg.IntOpt('quota_port',
default=50,
help=_('Number of ports allowed per tenant. '
'A negative value means unlimited.')),
cfg.StrOpt('quota_driver',
default=QUOTA_DB_DRIVER,
help=_('Default driver to use for quota checks')),
cfg.BoolOpt('track_quota_usage',
default=True,
help=_('Keep in track in the database of current resource '
'quota usage. Plugins which do not leverage the '
'neutron database should set this flag to False')),
]
# Register the configuration options # Register the configuration options
cfg.CONF.register_opts(quota_opts, 'QUOTAS') quota.register_quota_opts(quota.core_quota_opts)
class ConfDriver(object): class ConfDriver(object):