Add oslo_config and oslo_log to Ranger

Adds basic functionality for oslo_config and oslo_log to Ranger uuidgen

Change-Id: I041e4e2013fec83d3ff0b5befc581a455cb04ffe
This commit is contained in:
Nicholas Jones 2017-11-02 10:36:56 -05:00
parent e5b5c5981f
commit 8eae8053a4
10 changed files with 125 additions and 84 deletions

View File

@ -1,31 +0,0 @@
[DEFAULT]
api_workers = 1
debug = True
verbose = True
pecan_debug = True
region = local
#Log files location
log_dir = /var/log/ranger
local_repo = ranger_repo
cms_log_file: /var/log/orm/cms_rest.log
fms_log_file: /var/log/orm/fms_rest.log
ims_log_file: /var/log/orm/ims.log
rds_log_file: /var/log/orm/rds.log
uuidgen_log_file: /var/log/orm/uuidgen.log
audit_log_file: /var/log/orm/audit_server.log
rms_log_file: /var/log/orm/rms.log
orm_base_url: https://127.0.0.1
cms_listen_port: 7080
rms_listen_port: 8080
rds_http_listen_port: 8777
rds_listen_port: 8778
fms_listen_port: 8082
ims_listen_port: 8084
uuidgen_listen_port: 8090
audit_server_listen_port: 8776
[api]
# Address to bind the API server to
host = 0.0.0.0
# Port the bind the API server to
port = 9010

24
orm/_i18n.py Normal file
View File

@ -0,0 +1,24 @@
# 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.
"""oslo.i18n integration module.
See https://docs.openstack.org/oslo.i18n/latest/user/usage.html
"""
import oslo_i18n
DOMAIN = 'ranger'
_translators = oslo_i18n.TranslatorFactory(domain=DOMAIN)
# The primary translation function using the well-known name "_"
_ = _translators.primary

View File

@ -12,8 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from orm.common import config
from orm.services.id_generator.uuidgen import app
CONF = cfg.CONF
def main():
config.parse_args()
app.main()

69
orm/common/config.py Normal file
View File

@ -0,0 +1,69 @@
# 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.
"""
Configuration options registration.
"""
from oslo_config import cfg
from oslo_log import log as logging
CONF = cfg.CONF
api_opts = [
cfg.HostAddressOpt(
'host',
default='0.0.0.0',
help='Ranger API server host'
),
cfg.BoolOpt('ssl_verify', default=False, help='Enable HTTPS')
]
uuid_opts = [
cfg.PortOpt('port', default=7001, help='uuid server port'),
]
db_opts = [
cfg.StrOpt('connection', default='',
help='Ranger database connection string')
]
API_GROUP = 'api'
UUID_GROUP = 'uuid'
DB_GROUP = 'database'
CONF.register_opts(api_opts, group=API_GROUP)
CONF.register_opts(uuid_opts, group=UUID_GROUP)
CONF.register_opts(db_opts, group=DB_GROUP)
logging.register_options(CONF)
def list_opts():
return [
(API_GROUP, api_opts),
(UUID_GROUP, uuid_opts),
(DB_GROUP, db_opts)
]
def parse_args(args=None):
logging.setup(CONF, 'ranger')
CONF(
args=args,
project='ranger',
default_config_files=[]
)

View File

@ -1,8 +1,12 @@
import orm.base_config as config
from oslo_config import cfg
CONF = cfg.CONF
# Server Specific Configurations
server = {
'port': config.uuid['port'],
'host': config.orm_host
'port': CONF.uuid.port,
'host': CONF.api.host
}
# Pecan Application Configurations
app = {
@ -11,49 +15,10 @@ app = {
'debug': True,
}
logging = {
'root': {'level': 'INFO', 'handlers': ['console']},
'loggers': {
'uuidgen': {'level': 'DEBUG', 'handlers': ['console', 'Logfile'],
'propagate': False},
'pecan': {'level': 'DEBUG', 'handlers': ['console'],
'propagate': False},
'py.warnings': {'handlers': ['console']},
'__force_dict__': True
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'color'
},
'Logfile': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'maxBytes': 50000000,
'backupCount': 10,
'filename': config.uuid['log'],
'formatter': 'simple'
}
},
'formatters': {
'simple': {
'format': ('%(asctime)s %(levelname)-5.5s [%(name)s]'
'[%(threadName)s] %(message)s')
},
'color': {
'()': 'pecan.log.ColorFormatter',
'format': ('%(asctime)s [%(padded_color_levelname)s] [%(name)s]'
'[%(threadName)s] %(message)s'),
'__force_dict__': True
}
}
}
verify = config.ssl_verify
verify = CONF.api.ssl_verify
database = {
'connection_string': config.db_url + 'orm'
'connection_string': CONF.database.connection + '/orm'
}
# Custom Configurations must be in Python dictionary format::
#

View File

@ -1,19 +1,20 @@
import logging
import os
from oslo_log import log as logging
from pecan.commands import CommandRunner
from pecan import make_app
logger = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
def setup_app(config):
app_conf = dict(config.app)
app = make_app(app_conf.pop('root'),
logging=getattr(config, 'logging', {}),
**app_conf)
logger.info('Starting uuidgen...')
LOG.info('Starting uuidgen...')
return app

View File

@ -12,5 +12,6 @@ MySQL-python==1.2.5
requests==2.6.0
oslo.db==1.7.2
oslo.serialization
oslo.config
oslo.config>=4.6.0 # Apache-2.0
oslo.policy
oslo.log>=3.30.0 # Apache-2.0

View File

@ -24,10 +24,6 @@ setup-hooks =
[files]
packages = orm
data_files =
/etc/orm =
etc/orm.conf
[entry_points]
console_scripts=
@ -38,6 +34,8 @@ console_scripts=
orm-ims = orm.cmd.ims:main
orm-audit = orm.cmd.audit:main
orm-uuidgen = orm.cmd.uuidgen:main
oslo.config.opts =
ranger = orm.common.config:list_opts
[build_sphinx]
source-dir = doc/source

View File

@ -0,0 +1,4 @@
[DEFAULT]
output_file=etc/ranger.conf
wrap_width=79
namespace=ranger

View File

@ -39,6 +39,9 @@ commands =
[testenv:debug]
commands = oslo_debug_helper {posargs}
[testenv:genconfig]
commands = oslo-config-generator --config-file=tools/config/ranger-config-generator.conf
[flake8]
show-source = True
ignore = H301,F821,H202,H101,H104,H238,H401,H405,E501,F811,F403,H233,F841