Centralize config option: rpc periodic section

Centralize config option of rpc periodic section.
Replace oslo_conf cfg to magnum.conf.

Change-Id: Ic499369d16e7be79449a0e8ed5416b0ab92abc07
Implements: blueprint centralize-config-magnum
This commit is contained in:
Hieu LE 2016-08-22 10:31:53 +07:00
parent cc839e86af
commit 1a97476593
5 changed files with 51 additions and 29 deletions

View File

@ -15,11 +15,11 @@
"""Common RPC service and API tools for Magnum.""" """Common RPC service and API tools for Magnum."""
import eventlet import eventlet
from oslo_config import cfg
import oslo_messaging as messaging import oslo_messaging as messaging
from oslo_service import service from oslo_service import service
from magnum.common import rpc from magnum.common import rpc
import magnum.conf
from magnum.objects import base as objects_base from magnum.objects import base as objects_base
from magnum.service import periodic from magnum.service import periodic
from magnum.servicegroup import magnum_service_periodic as servicegroup from magnum.servicegroup import magnum_service_periodic as servicegroup
@ -41,25 +41,7 @@ TRANSPORT_ALIASES = {
'magnum.openstack.common.rpc.impl_zmq': 'zmq', 'magnum.openstack.common.rpc.impl_zmq': 'zmq',
} }
periodic_opts = [ CONF = magnum.conf.CONF
cfg.BoolOpt('periodic_global_stack_list',
default=False,
help="List Heat stacks globally when syncing clusters. "
"Default is to do retrieve each cluster's stack "
"individually. Reduces number of requests against "
"Heat API if enabled but requires changes to Heat's "
"policy.json."),
cfg.BoolOpt('periodic_enable',
default=True,
help='Enable periodic tasks.'),
cfg.IntOpt('periodic_interval_max',
default=60,
help='Max interval size between periodic tasks execution in '
'seconds.'),
]
CONF = cfg.CONF
CONF.register_opts(periodic_opts)
class Service(service.Service): class Service(service.Service):
@ -68,7 +50,7 @@ class Service(service.Service):
super(Service, self).__init__() super(Service, self).__init__()
serializer = rpc.RequestContextSerializer( serializer = rpc.RequestContextSerializer(
objects_base.MagnumObjectSerializer()) objects_base.MagnumObjectSerializer())
transport = messaging.get_transport(cfg.CONF, transport = messaging.get_transport(CONF,
aliases=TRANSPORT_ALIASES) aliases=TRANSPORT_ALIASES)
# TODO(asalkeld) add support for version='x.y' # TODO(asalkeld) add support for version='x.y'
target = messaging.Target(topic=topic, server=server) target = messaging.Target(topic=topic, server=server)
@ -102,7 +84,7 @@ class API(object):
objects_base.MagnumObjectSerializer()) objects_base.MagnumObjectSerializer())
if transport is None: if transport is None:
exmods = rpc.get_allowed_exmods() exmods = rpc.get_allowed_exmods()
transport = messaging.get_transport(cfg.CONF, transport = messaging.get_transport(CONF,
allowed_remote_exmods=exmods, allowed_remote_exmods=exmods,
aliases=TRANSPORT_ALIASES) aliases=TRANSPORT_ALIASES)
self._context = context self._context = context

View File

@ -32,6 +32,7 @@ from magnum.conf import magnum_client
from magnum.conf import neutron from magnum.conf import neutron
from magnum.conf import nova from magnum.conf import nova
from magnum.conf import paths from magnum.conf import paths
from magnum.conf import rpc
from magnum.conf import utils from magnum.conf import utils
# from magnum.conf import x509 # from magnum.conf import x509
@ -54,5 +55,6 @@ magnum_client.register_opts(CONF)
neutron.register_opts(CONF) neutron.register_opts(CONF)
nova.register_opts(CONF) nova.register_opts(CONF)
paths.register_opts(CONF) paths.register_opts(CONF)
rpc.register_opts(CONF)
utils.register_opts(CONF) utils.register_opts(CONF)
# x509.register_opts(CONF) # x509.register_opts(CONF)

41
magnum/conf/rpc.py Normal file
View File

@ -0,0 +1,41 @@
# 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
periodic_opts = [
cfg.BoolOpt('periodic_global_stack_list',
default=False,
help="List Heat stacks globally when syncing clusters. "
"Default is to do retrieve each cluster's stack "
"individually. Reduces number of requests against "
"Heat API if enabled but requires changes to Heat's "
"policy.json."),
cfg.BoolOpt('periodic_enable',
default=True,
help='Enable periodic tasks.'),
cfg.IntOpt('periodic_interval_max',
default=60,
help='Max interval size between periodic tasks execution in '
'seconds.'),
]
def register_opts(conf):
conf.register_opts(periodic_opts)
def list_opts():
return {
"DEFAULT": periodic_opts
}

View File

@ -17,8 +17,8 @@ import itertools
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.docker_utils
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.db import magnum.db
@ -27,10 +27,7 @@ import magnum.drivers.common.template_def
def list_opts(): def list_opts():
return [ return [
('DEFAULT', ('DEFAULT', magnum.common.service.service_opts),
itertools.chain(magnum.common.rpc_service.periodic_opts,
magnum.common.service.service_opts,
)),
('docker', magnum.common.docker_utils.docker_opts), ('docker', magnum.common.docker_utils.docker_opts),
('trust', magnum.common.keystone.trust_opts), ('trust', magnum.common.keystone.trust_opts),
('x509', magnum.common.x509.config.x509_opts), ('x509', magnum.common.x509.config.x509_opts),

View File

@ -16,7 +16,6 @@
import functools import functools
from heatclient import exc as heat_exc from heatclient import exc as heat_exc
from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_service import periodic_task from oslo_service import periodic_task
import six import six
@ -26,6 +25,7 @@ from magnum.common import context
from magnum.common import exception from magnum.common import exception
from magnum.common import rpc from magnum.common import rpc
from magnum.conductor import monitors from magnum.conductor import monitors
import magnum.conf
from magnum.i18n import _ from magnum.i18n import _
from magnum.i18n import _LI from magnum.i18n import _LI
from magnum.i18n import _LW from magnum.i18n import _LW
@ -33,7 +33,7 @@ from magnum import objects
from magnum.objects import fields from magnum.objects import fields
CONF = cfg.CONF CONF = magnum.conf.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)