From cfe5b4ed5cb770518b13848f33c517f749564782 Mon Sep 17 00:00:00 2001 From: Hieu LE Date: Wed, 17 Aug 2016 10:41:47 +0700 Subject: [PATCH] Centralize config option: api section Centralize config option of API section. Replace oslo_conf cfg to magnum.conf. Change-Id: I0589014ab8eb70f0f6551bb23808d3b9edc580c1 Implements: blueprint centralize-config-magnum --- magnum/api/app.py | 39 ++------------ magnum/api/utils.py | 4 +- magnum/cmd/api.py | 9 ++-- magnum/conf/__init__.py | 4 +- magnum/conf/api.py | 54 +++++++++++++++++++ magnum/opts.py | 3 +- .../unit/api/controllers/v1/test_utils.py | 4 +- 7 files changed, 70 insertions(+), 47 deletions(-) create mode 100644 magnum/conf/api.py diff --git a/magnum/api/app.py b/magnum/api/app.py index 6f1c8166fc..60297c04a5 100644 --- a/magnum/api/app.py +++ b/magnum/api/app.py @@ -19,41 +19,10 @@ import pecan from magnum.api import config as api_config from magnum.api import middleware from magnum.common import config as common_config +import magnum.conf from magnum.i18n import _LI -# Register options for the service -API_SERVICE_OPTS = [ - cfg.PortOpt('port', - default=9511, - help='The port for the Magnum API server.'), - cfg.IPOpt('host', - default='127.0.0.1', - help='The listen IP for the Magnum API server.'), - cfg.IntOpt('max_limit', - default=1000, - help='The maximum number of items returned in a single ' - 'response from a collection resource.'), - cfg.StrOpt('api_paste_config', - default="api-paste.ini", - help="Configuration file for WSGI definition of API." - ), - cfg.StrOpt('ssl_cert_file', - help="This option allows setting path to the SSL certificate " - "of API server. "), - cfg.StrOpt('ssl_key_file', - help="This option specifies the path to the file where SSL " - "private key of API server is stored when SSL is in " - "effect. "), - cfg.BoolOpt('enabled_ssl', - default=False, - help='Enable SSL Magnum API service') -] - -CONF = cfg.CONF -opt_group = cfg.OptGroup(name='api', - title='Options for the magnum-api service') -CONF.register_group(opt_group) -CONF.register_opts(API_SERVICE_OPTS, opt_group) +CONF = magnum.conf.CONF LOG = log.getLogger(__name__) @@ -83,14 +52,14 @@ def setup_app(config=None): def load_app(): cfg_file = None - cfg_path = cfg.CONF.api.api_paste_config + cfg_path = CONF.api.api_paste_config if not os.path.isabs(cfg_path): cfg_file = CONF.find_file(cfg_path) elif os.path.exists(cfg_path): cfg_file = cfg_path if not cfg_file: - raise cfg.ConfigFilesNotFoundError([cfg.CONF.api.api_paste_config]) + raise cfg.ConfigFilesNotFoundError([CONF.api.api_paste_config]) LOG.info(_LI("Full WSGI config used: %s"), cfg_file) return deploy.loadapp("config:" + cfg_file) diff --git a/magnum/api/utils.py b/magnum/api/utils.py index 1067071941..72fc0eed92 100644 --- a/magnum/api/utils.py +++ b/magnum/api/utils.py @@ -14,18 +14,18 @@ # under the License. import jsonpatch -from oslo_config import cfg from oslo_utils import uuidutils import pecan import wsme from magnum.common import exception from magnum.common import utils +import magnum.conf from magnum.i18n import _ from magnum.i18n import _LE from magnum import objects -CONF = cfg.CONF +CONF = magnum.conf.CONF JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchException, diff --git a/magnum/cmd/api.py b/magnum/cmd/api.py index af81e41648..41e54d1211 100644 --- a/magnum/cmd/api.py +++ b/magnum/cmd/api.py @@ -17,19 +17,20 @@ import os import sys -from oslo_config import cfg from oslo_log import log as logging from oslo_reports import guru_meditation_report as gmr from werkzeug import serving from magnum.api import app as api_app from magnum.common import service +import magnum.conf from magnum.i18n import _ from magnum.i18n import _LI from magnum.objects import base from magnum import version -CONF = cfg.CONF + +CONF = magnum.conf.CONF LOG = logging.getLogger(__name__) @@ -65,11 +66,11 @@ def main(): use_ssl = CONF.api.enabled_ssl # Create the WSGI server and start it - host, port = cfg.CONF.api.host, cfg.CONF.api.port + host, port = CONF.api.host, CONF.api.port LOG.info(_LI('Starting server in PID %s'), os.getpid()) LOG.debug("Configuration:") - cfg.CONF.log_opt_values(LOG, logging.DEBUG) + CONF.log_opt_values(LOG, logging.DEBUG) LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'), dict(proto="https" if use_ssl else "http", host=host, port=port)) diff --git a/magnum/conf/__init__.py b/magnum/conf/__init__.py index 07a831e803..ce8422a031 100644 --- a/magnum/conf/__init__.py +++ b/magnum/conf/__init__.py @@ -15,7 +15,7 @@ from oslo_config import cfg -# from magnum.conf import api +from magnum.conf import api # from magnum.conf import barbican # from magnum.conf import certificates # from magnum.conf import cinder @@ -34,7 +34,7 @@ from oslo_config import cfg CONF = cfg.CONF -# api.register_opts(CONF) +api.register_opts(CONF) # barbican.register_opts(CONF) # cluster.register_opts(CONF) # cluster_templates.register_opts(CONF) diff --git a/magnum/conf/api.py b/magnum/conf/api.py new file mode 100644 index 0000000000..11756c9191 --- /dev/null +++ b/magnum/conf/api.py @@ -0,0 +1,54 @@ +# 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 + +api_group = cfg.OptGroup(name='api', + title='Options for the magnum-api service') + +api_service_opts = [ + cfg.PortOpt('port', + default=9511, + help='The port for the Magnum API server.'), + cfg.IPOpt('host', + default='127.0.0.1', + help='The listen IP for the Magnum API server.'), + cfg.IntOpt('max_limit', + default=1000, + help='The maximum number of items returned in a single ' + 'response from a collection resource.'), + cfg.StrOpt('api_paste_config', + default="api-paste.ini", + help="Configuration file for WSGI definition of API." + ), + cfg.StrOpt('ssl_cert_file', + help="This option allows setting path to the SSL certificate " + "of API server. "), + cfg.StrOpt('ssl_key_file', + help="This option specifies the path to the file where SSL " + "private key of API server is stored when SSL is in " + "effect. "), + cfg.BoolOpt('enabled_ssl', + default=False, + help='Enable SSL Magnum API service') +] + + +def register_opts(conf): + conf.register_group(api_group) + conf.register_opts(api_service_opts, group=api_group) + + +def list_opts(): + return { + api_group: api_service_opts + } diff --git a/magnum/opts.py b/magnum/opts.py index d8389dc07e..fed9219b2b 100644 --- a/magnum/opts.py +++ b/magnum/opts.py @@ -15,12 +15,12 @@ import itertools -import magnum.api.app import magnum.api.validation import magnum.common.cert_manager from magnum.common.cert_manager import local_cert_manager import magnum.common.clients import magnum.common.exception +import magnum.common.rpc_service import magnum.common.service import magnum.common.x509.config import magnum.conductor.config @@ -37,7 +37,6 @@ def list_opts(): magnum.common.rpc_service.periodic_opts, magnum.common.service.service_opts, )), - ('api', magnum.api.app.API_SERVICE_OPTS), ('cluster', magnum.drivers.common.template_def.template_def_opts), ('conductor', magnum.conductor.config.SERVICE_OPTS), ('database', magnum.db.sql_opts), diff --git a/magnum/tests/unit/api/controllers/v1/test_utils.py b/magnum/tests/unit/api/controllers/v1/test_utils.py index 267d3fc3b8..6d670e9943 100644 --- a/magnum/tests/unit/api/controllers/v1/test_utils.py +++ b/magnum/tests/unit/api/controllers/v1/test_utils.py @@ -15,16 +15,16 @@ import jsonpatch import mock -from oslo_config import cfg from oslo_utils import uuidutils import wsme from magnum.api import utils from magnum.common import exception +import magnum.conf from magnum.tests.unit.api import base -CONF = cfg.CONF +CONF = magnum.conf.CONF class TestApiUtils(base.FunctionalTest):