From 68a4b4729ae0123381f8fa869134037f631b66d8 Mon Sep 17 00:00:00 2001 From: Allen Gao Date: Mon, 4 Apr 2016 13:19:28 +0800 Subject: [PATCH] config options: centralize quota options The quota options got moved from "nova/quota.py" to the new central location "nova/conf/quota.py". Change-Id: I54c38ee3fcc086b222eb89ea1377e1906f1bc617 Implements: blueprint centralize-config-options-newton --- nova/conf/__init__.py | 2 + nova/conf/quota.py | 93 +++++++++++++++++++++++++++++++++++++++ nova/db/sqlalchemy/api.py | 4 +- nova/opts.py | 2 - nova/quota.py | 71 +----------------------------- 5 files changed, 99 insertions(+), 73 deletions(-) create mode 100644 nova/conf/quota.py diff --git a/nova/conf/__init__.py b/nova/conf/__init__.py index f1062c1bbb43..831a7b536eb8 100644 --- a/nova/conf/__init__.py +++ b/nova/conf/__init__.py @@ -62,6 +62,7 @@ from nova.conf import neutron from nova.conf import novnc # from nova.conf import osapi_v21 from nova.conf import pci +from nova.conf import quota from nova.conf import rdp from nova.conf import remote_debug from nova.conf import rpc @@ -128,6 +129,7 @@ neutron.register_opts(CONF) novnc.register_opts(CONF) # osapi_v21.register_opts(CONF) pci.register_opts(CONF) +quota.register_opts(CONF) rdp.register_opts(CONF) rpc.register_opts(CONF) scheduler.register_opts(CONF) diff --git a/nova/conf/quota.py b/nova/conf/quota.py new file mode 100644 index 000000000000..261a80cdcd55 --- /dev/null +++ b/nova/conf/quota.py @@ -0,0 +1,93 @@ +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# 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 + +quota_opts = [ + cfg.IntOpt('quota_instances', + default=10, + help='Number of instances allowed per project'), + cfg.IntOpt('quota_cores', + default=20, + help='Number of instance cores allowed per project'), + cfg.IntOpt('quota_ram', + default=50 * 1024, + help='Megabytes of instance RAM allowed per project'), + cfg.IntOpt('quota_floating_ips', + default=10, + help='Number of floating IPs allowed per project'), + cfg.IntOpt('quota_fixed_ips', + default=-1, + help='Number of fixed IPs allowed per project (this should be ' + 'at least the number of instances allowed)'), + cfg.IntOpt('quota_metadata_items', + default=128, + help='Number of metadata items allowed per instance'), + cfg.IntOpt('quota_injected_files', + default=5, + help='Number of injected files allowed'), + cfg.IntOpt('quota_injected_file_content_bytes', + default=10 * 1024, + help='Number of bytes allowed per injected file'), + cfg.IntOpt('quota_injected_file_path_length', + default=255, + help='Length of injected file path'), + cfg.IntOpt('quota_security_groups', + default=10, + help='Number of security groups per project'), + cfg.IntOpt('quota_security_group_rules', + default=20, + help='Number of security rules per security group'), + cfg.IntOpt('quota_key_pairs', + default=100, + help='Number of key pairs per user'), + cfg.IntOpt('quota_server_groups', + default=10, + help='Number of server groups per project'), + cfg.IntOpt('quota_server_group_members', + default=10, + help='Number of servers per server group'), + cfg.IntOpt('reservation_expire', + default=86400, + help='Number of seconds until a reservation expires'), + cfg.IntOpt('until_refresh', + default=0, + help='Count of reservations until usage is refreshed. This ' + 'defaults to 0(off) to avoid additional load but it is ' + 'useful to turn on to help keep quota usage up to date ' + 'and reduce the impact of out of sync usage issues.'), + cfg.IntOpt('max_age', + default=0, + help='Number of seconds between subsequent usage refreshes. ' + 'This defaults to 0(off) to avoid additional load but it ' + 'is useful to turn on to help keep quota usage up to date ' + 'and reduce the impact of out of sync usage issues. ' + 'Note that quotas are not updated on a periodic task, ' + 'they will update on a new reservation if max_age has ' + 'passed since the last reservation'), + cfg.StrOpt('quota_driver', + default='nova.quota.DbQuotaDriver', + help='Default driver to use for quota checks'), + ] + + +def register_opts(conf): + conf.register_opts(quota_opts) + + +def list_opts(): + return {'DEFAULT': quota_opts} diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 9c086aba0e1f..d950d2173c78 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -61,6 +61,7 @@ from sqlalchemy.sql import true from nova import block_device from nova.compute import task_states from nova.compute import vm_states +import nova.conf import nova.context from nova.db.sqlalchemy import models from nova import exception @@ -125,11 +126,10 @@ api_db_opts = [ 'SQLAlchemy.'), ] -CONF = cfg.CONF +CONF = nova.conf.CONF CONF.register_opts(db_opts) CONF.register_opts(oslo_db_options.database_opts, 'database') CONF.register_opts(api_db_opts, group='api_database') -CONF.import_opt('until_refresh', 'nova.quota') LOG = logging.getLogger(__name__) diff --git a/nova/opts.py b/nova/opts.py index b6a415e80638..bad27d6659ce 100644 --- a/nova/opts.py +++ b/nova/opts.py @@ -33,7 +33,6 @@ import nova.ipv6.api import nova.netconf import nova.notifications import nova.paths -import nova.quota import nova.servicegroup.api import nova.spice import nova.volume @@ -57,7 +56,6 @@ def list_opts(): nova.netconf.netconf_opts, nova.notifications.notify_opts, nova.paths.path_opts, - nova.quota.quota_opts, nova.volume._volume_opts, )), ('cinder', nova.volume.cinder.cinder_opts), diff --git a/nova/quota.py b/nova/quota.py index 6b26f372fdd1..c0f090d6c9c6 100644 --- a/nova/quota.py +++ b/nova/quota.py @@ -18,12 +18,12 @@ import datetime -from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils from oslo_utils import timeutils import six +import nova.conf from nova import db from nova import exception from nova.i18n import _LE @@ -31,75 +31,8 @@ from nova import objects LOG = logging.getLogger(__name__) -quota_opts = [ - cfg.IntOpt('quota_instances', - default=10, - help='Number of instances allowed per project'), - cfg.IntOpt('quota_cores', - default=20, - help='Number of instance cores allowed per project'), - cfg.IntOpt('quota_ram', - default=50 * 1024, - help='Megabytes of instance RAM allowed per project'), - cfg.IntOpt('quota_floating_ips', - default=10, - help='Number of floating IPs allowed per project'), - cfg.IntOpt('quota_fixed_ips', - default=-1, - help='Number of fixed IPs allowed per project (this should be ' - 'at least the number of instances allowed)'), - cfg.IntOpt('quota_metadata_items', - default=128, - help='Number of metadata items allowed per instance'), - cfg.IntOpt('quota_injected_files', - default=5, - help='Number of injected files allowed'), - cfg.IntOpt('quota_injected_file_content_bytes', - default=10 * 1024, - help='Number of bytes allowed per injected file'), - cfg.IntOpt('quota_injected_file_path_length', - default=255, - help='Length of injected file path'), - cfg.IntOpt('quota_security_groups', - default=10, - help='Number of security groups per project'), - cfg.IntOpt('quota_security_group_rules', - default=20, - help='Number of security rules per security group'), - cfg.IntOpt('quota_key_pairs', - default=100, - help='Number of key pairs per user'), - cfg.IntOpt('quota_server_groups', - default=10, - help='Number of server groups per project'), - cfg.IntOpt('quota_server_group_members', - default=10, - help='Number of servers per server group'), - cfg.IntOpt('reservation_expire', - default=86400, - help='Number of seconds until a reservation expires'), - cfg.IntOpt('until_refresh', - default=0, - help='Count of reservations until usage is refreshed. This ' - 'defaults to 0(off) to avoid additional load but it is ' - 'useful to turn on to help keep quota usage up to date ' - 'and reduce the impact of out of sync usage issues.'), - cfg.IntOpt('max_age', - default=0, - help='Number of seconds between subsequent usage refreshes. ' - 'This defaults to 0(off) to avoid additional load but it ' - 'is useful to turn on to help keep quota usage up to date ' - 'and reduce the impact of out of sync usage issues. ' - 'Note that quotas are not updated on a periodic task, ' - 'they will update on a new reservation if max_age has ' - 'passed since the last reservation'), - cfg.StrOpt('quota_driver', - default='nova.quota.DbQuotaDriver', - help='Default driver to use for quota checks'), - ] -CONF = cfg.CONF -CONF.register_opts(quota_opts) +CONF = nova.conf.CONF class DbQuotaDriver(object):