Config refactoring
This splits the configuration module into a package with multiple modules. Additionally adds support for oslo-config-generator. Additionally adds mixmatch.conf to .gitignore Change-Id: I735c6e852ef3cddb6dff654e1b8777ba239b91ab
This commit is contained in:
89
mixmatch/config/__init__.py
Normal file
89
mixmatch/config/__init__.py
Normal file
@@ -0,0 +1,89 @@
|
||||
# Copyright 2017 Massachusetts Open Cloud
|
||||
#
|
||||
# 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 os import path
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from mixmatch.config import auth
|
||||
from mixmatch.config import cache
|
||||
from mixmatch.config import default
|
||||
from mixmatch.config import service_providers
|
||||
|
||||
LOG = log.getLogger('root')
|
||||
CONF = cfg.CONF
|
||||
|
||||
# Note(knikolla): Configuration modules are registered in the list below.
|
||||
# Order matters, and they are loaded in the defined order.
|
||||
#
|
||||
# Each module must define the following variables and functions.
|
||||
# * GROUP - oslo_config.cfg.OptGroup or None
|
||||
# * OPTS - list of oslo_config.cfg.{Int,Str,Bool,etc}Opt or []
|
||||
# * pre_config() - function is executed at module import time before OPTS
|
||||
# are registered.
|
||||
# * post_config() - function is executed after the configuration files have
|
||||
# been loaded.
|
||||
MODULES = [
|
||||
default,
|
||||
cache,
|
||||
auth,
|
||||
service_providers
|
||||
]
|
||||
|
||||
|
||||
def load_from_file():
|
||||
"""Load options from the configuration file."""
|
||||
conf_files = [f for f in ['mixmatch.conf',
|
||||
'etc/mixmatch/mixmatch.conf',
|
||||
'/etc/mixmatch/mixmatch.conf'] if path.isfile(f)]
|
||||
if conf_files is not []:
|
||||
CONF(default_config_files=conf_files)
|
||||
|
||||
|
||||
def register_opts():
|
||||
for option_module in MODULES:
|
||||
if option_module.GROUP:
|
||||
CONF.register_group(option_module.GROUP)
|
||||
|
||||
if option_module.OPTS:
|
||||
CONF.register_opts(option_module.OPTS, option_module.GROUP)
|
||||
|
||||
|
||||
def list_opts():
|
||||
return [(m.GROUP, m.OPTS) for m in MODULES]
|
||||
|
||||
|
||||
def pre_config():
|
||||
log.register_options(CONF)
|
||||
|
||||
for option_module in MODULES:
|
||||
option_module.pre_config(CONF)
|
||||
|
||||
register_opts()
|
||||
|
||||
|
||||
def post_config():
|
||||
for option_module in MODULES:
|
||||
option_module.post_config(CONF)
|
||||
|
||||
log.setup(CONF, 'demo')
|
||||
|
||||
|
||||
def configure():
|
||||
load_from_file()
|
||||
post_config()
|
||||
|
||||
|
||||
pre_config()
|
||||
58
mixmatch/config/auth.py
Normal file
58
mixmatch/config/auth.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# Copyright 2017 Massachusetts Open Cloud
|
||||
#
|
||||
# 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 mixmatch.config import cache
|
||||
|
||||
GROUP = cfg.OptGroup(name='auth', title='Keystone Config Group')
|
||||
|
||||
OPTS = [
|
||||
cfg.StrOpt('auth_url',
|
||||
default='http://localhost:35357/v3',
|
||||
help='Keystone AUTH URL'),
|
||||
|
||||
cfg.StrOpt('username',
|
||||
default='admin',
|
||||
help='Proxy username'),
|
||||
|
||||
cfg.StrOpt('user_domain_id',
|
||||
default='default',
|
||||
help='Proxy user domain id'),
|
||||
|
||||
cfg.StrOpt('password',
|
||||
default='nomoresecrete',
|
||||
help='Proxy user password'),
|
||||
|
||||
cfg.StrOpt('project_name',
|
||||
default='admin',
|
||||
help='Proxy project name'),
|
||||
|
||||
cfg.StrOpt('project_domain_id',
|
||||
default='default',
|
||||
help='Proxy project domain id')
|
||||
]
|
||||
|
||||
MEMOIZE = None
|
||||
|
||||
|
||||
def pre_config(conf):
|
||||
global MEMOIZE
|
||||
|
||||
cache.register_region('auth')
|
||||
MEMOIZE = cache.get_decorator(conf, name='auth', group='auth')
|
||||
|
||||
|
||||
def post_config(conf):
|
||||
pass
|
||||
49
mixmatch/config/cache.py
Normal file
49
mixmatch/config/cache.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# Copyright 2017 Massachusetts Open Cloud
|
||||
#
|
||||
# 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 oslo_cache import core
|
||||
|
||||
GROUP = None
|
||||
|
||||
OPTS = [
|
||||
cfg.BoolOpt('caching',
|
||||
default=True,
|
||||
help='Enable caching.'),
|
||||
|
||||
cfg.IntOpt('cache_time',
|
||||
default=600,
|
||||
help='How long to cache things.'),
|
||||
]
|
||||
|
||||
_REGIONS = {}
|
||||
|
||||
|
||||
def pre_config(conf):
|
||||
core.configure(conf)
|
||||
|
||||
|
||||
def post_config(conf):
|
||||
for _, region in _REGIONS.items():
|
||||
core.configure_cache_region(conf, region)
|
||||
|
||||
|
||||
def register_region(name):
|
||||
_REGIONS[name] = core.create_region()
|
||||
|
||||
|
||||
def get_decorator(conf, name, group):
|
||||
return core.get_memoization_decorator(conf,
|
||||
_REGIONS[name],
|
||||
group=group)
|
||||
51
mixmatch/config/default.py
Normal file
51
mixmatch/config/default.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# Copyright 2017 Massachusetts Open Cloud
|
||||
#
|
||||
# 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
|
||||
|
||||
GROUP = None
|
||||
|
||||
OPTS = [
|
||||
cfg.IntOpt('port',
|
||||
default=5001,
|
||||
help='Web Server Port'),
|
||||
|
||||
cfg.ListOpt('service_providers',
|
||||
default=[],
|
||||
help='List of service providers'),
|
||||
|
||||
cfg.BoolOpt('search_by_broadcast',
|
||||
default=False,
|
||||
help='Search All Service Providers on Unknown Resource ID'),
|
||||
|
||||
cfg.BoolOpt('aggregation',
|
||||
default=False,
|
||||
help='Enable Aggregation when listing resources.'),
|
||||
|
||||
cfg.ListOpt('image_api_versions',
|
||||
default=['v2.3', 'v2.2', 'v2.1', 'v2.0', 'v1.1', 'v1.0'],
|
||||
help='List of supported image api versions'),
|
||||
|
||||
cfg.ListOpt('volume_api_versions',
|
||||
default=['v3.0', 'v2.0', 'v1.0'],
|
||||
help='List of supported volume api versions'),
|
||||
]
|
||||
|
||||
|
||||
def pre_config(conf):
|
||||
pass
|
||||
|
||||
|
||||
def post_config(conf):
|
||||
pass
|
||||
64
mixmatch/config/service_providers.py
Normal file
64
mixmatch/config/service_providers.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# Copyright 2017 Massachusetts Open Cloud
|
||||
#
|
||||
# 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
|
||||
|
||||
GROUP = None
|
||||
|
||||
OPTS = []
|
||||
|
||||
SP_OPTS = [
|
||||
cfg.StrOpt('sp_name',
|
||||
default="default",
|
||||
help='SP ID in Keystone Catalog. Omit for local.'),
|
||||
|
||||
cfg.StrOpt('messagebus',
|
||||
help='URI to connect to message bus'),
|
||||
|
||||
cfg.StrOpt('services',
|
||||
default=None,
|
||||
help='Enabled services for this service provider.'),
|
||||
|
||||
cfg.StrOpt('auth_url',
|
||||
default=None,
|
||||
help='Keystone AUTH URL for Service Provider'),
|
||||
|
||||
cfg.StrOpt('image_endpoint',
|
||||
default=None,
|
||||
help="Image Endpoint for Service Provider"),
|
||||
|
||||
cfg.StrOpt('volume_endpoint',
|
||||
default=None,
|
||||
help="Volume Endpoint for Service Provider"),
|
||||
|
||||
cfg.ListOpt('enabled_services',
|
||||
default=['image', 'volume'],
|
||||
help="Services to enable for Service Provider")
|
||||
]
|
||||
|
||||
|
||||
def pre_config(conf):
|
||||
pass
|
||||
|
||||
|
||||
def post_config(conf):
|
||||
for service_provider in conf.service_providers:
|
||||
sp_group = cfg.OptGroup(name='sp_%s' % service_provider,
|
||||
title=service_provider)
|
||||
conf.register_opts(SP_OPTS, sp_group)
|
||||
|
||||
|
||||
def get(conf, sp_id):
|
||||
"""Get the configuration opject for a specifc service provider."""
|
||||
return conf.__getattr__('sp_%s' % sp_id)
|
||||
Reference in New Issue
Block a user