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
This commit is contained in:
Hieu LE 2016-08-17 10:41:47 +07:00
parent 8020245e18
commit cfe5b4ed5c
7 changed files with 70 additions and 47 deletions

View File

@ -19,41 +19,10 @@ import pecan
from magnum.api import config as api_config from magnum.api import config as api_config
from magnum.api import middleware from magnum.api import middleware
from magnum.common import config as common_config from magnum.common import config as common_config
import magnum.conf
from magnum.i18n import _LI from magnum.i18n import _LI
# Register options for the service CONF = magnum.conf.CONF
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)
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -83,14 +52,14 @@ def setup_app(config=None):
def load_app(): def load_app():
cfg_file = None 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): if not os.path.isabs(cfg_path):
cfg_file = CONF.find_file(cfg_path) cfg_file = CONF.find_file(cfg_path)
elif os.path.exists(cfg_path): elif os.path.exists(cfg_path):
cfg_file = cfg_path cfg_file = cfg_path
if not cfg_file: 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) LOG.info(_LI("Full WSGI config used: %s"), cfg_file)
return deploy.loadapp("config:" + cfg_file) return deploy.loadapp("config:" + cfg_file)

View File

@ -14,18 +14,18 @@
# under the License. # under the License.
import jsonpatch import jsonpatch
from oslo_config import cfg
from oslo_utils import uuidutils from oslo_utils import uuidutils
import pecan import pecan
import wsme import wsme
from magnum.common import exception from magnum.common import exception
from magnum.common import utils from magnum.common import utils
import magnum.conf
from magnum.i18n import _ from magnum.i18n import _
from magnum.i18n import _LE from magnum.i18n import _LE
from magnum import objects from magnum import objects
CONF = cfg.CONF CONF = magnum.conf.CONF
JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchException, JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchException,

View File

@ -17,19 +17,20 @@
import os import os
import sys import sys
from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_reports import guru_meditation_report as gmr from oslo_reports import guru_meditation_report as gmr
from werkzeug import serving from werkzeug import serving
from magnum.api import app as api_app from magnum.api import app as api_app
from magnum.common import service from magnum.common import service
import magnum.conf
from magnum.i18n import _ from magnum.i18n import _
from magnum.i18n import _LI from magnum.i18n import _LI
from magnum.objects import base from magnum.objects import base
from magnum import version from magnum import version
CONF = cfg.CONF
CONF = magnum.conf.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -65,11 +66,11 @@ def main():
use_ssl = CONF.api.enabled_ssl use_ssl = CONF.api.enabled_ssl
# Create the WSGI server and start it # 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.info(_LI('Starting server in PID %s'), os.getpid())
LOG.debug("Configuration:") 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'), LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'),
dict(proto="https" if use_ssl else "http", host=host, port=port)) dict(proto="https" if use_ssl else "http", host=host, port=port))

View File

@ -15,7 +15,7 @@
from oslo_config import cfg from oslo_config import cfg
# from magnum.conf import api from magnum.conf import api
# from magnum.conf import barbican # from magnum.conf import barbican
# from magnum.conf import certificates # from magnum.conf import certificates
# from magnum.conf import cinder # from magnum.conf import cinder
@ -34,7 +34,7 @@ from oslo_config import cfg
CONF = cfg.CONF CONF = cfg.CONF
# api.register_opts(CONF) api.register_opts(CONF)
# barbican.register_opts(CONF) # barbican.register_opts(CONF)
# cluster.register_opts(CONF) # cluster.register_opts(CONF)
# cluster_templates.register_opts(CONF) # cluster_templates.register_opts(CONF)

54
magnum/conf/api.py Normal file
View File

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

View File

@ -15,12 +15,12 @@
import itertools import itertools
import magnum.api.app
import magnum.api.validation import magnum.api.validation
import magnum.common.cert_manager import magnum.common.cert_manager
from magnum.common.cert_manager import local_cert_manager from magnum.common.cert_manager import local_cert_manager
import magnum.common.clients import magnum.common.clients
import magnum.common.exception import magnum.common.exception
import magnum.common.rpc_service
import magnum.common.service import magnum.common.service
import magnum.common.x509.config import magnum.common.x509.config
import magnum.conductor.config import magnum.conductor.config
@ -37,7 +37,6 @@ def list_opts():
magnum.common.rpc_service.periodic_opts, magnum.common.rpc_service.periodic_opts,
magnum.common.service.service_opts, magnum.common.service.service_opts,
)), )),
('api', magnum.api.app.API_SERVICE_OPTS),
('cluster', magnum.drivers.common.template_def.template_def_opts), ('cluster', magnum.drivers.common.template_def.template_def_opts),
('conductor', magnum.conductor.config.SERVICE_OPTS), ('conductor', magnum.conductor.config.SERVICE_OPTS),
('database', magnum.db.sql_opts), ('database', magnum.db.sql_opts),

View File

@ -15,16 +15,16 @@
import jsonpatch import jsonpatch
import mock import mock
from oslo_config import cfg
from oslo_utils import uuidutils from oslo_utils import uuidutils
import wsme import wsme
from magnum.api import utils from magnum.api import utils
from magnum.common import exception from magnum.common import exception
import magnum.conf
from magnum.tests.unit.api import base from magnum.tests.unit.api import base
CONF = cfg.CONF CONF = magnum.conf.CONF
class TestApiUtils(base.FunctionalTest): class TestApiUtils(base.FunctionalTest):