"Fossies" - the Fresh Open Source Software Archive

Member "monasca-log-api-2.9.0/monasca_log_api/config.py" (1 Apr 2019, 2644 Bytes) of package /linux/misc/openstack/monasca-log-api-2.9.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "config.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.7.0_vs_2.9.0.

    1 # Copyright 2017 FUJITSU LIMITED
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 
   15 import sys
   16 
   17 from oslo_config import cfg
   18 from oslo_log import log
   19 from oslo_policy import opts as policy_opts
   20 
   21 from monasca_log_api import conf
   22 from monasca_log_api import version
   23 
   24 CONF = conf.CONF
   25 LOG = log.getLogger(__name__)
   26 
   27 _CONF_LOADED = False
   28 _GUNICORN_MARKER = 'gunicorn'
   29 
   30 
   31 def _is_running_under_gunicorn():
   32     """Evaluates if api runs under gunicorn"""
   33     content = filter(lambda x: x != sys.executable and _GUNICORN_MARKER in x,
   34                      sys.argv or [])
   35     return len(list(content) if not isinstance(content, list) else content) > 0
   36 
   37 
   38 def get_config_files():
   39     """Get the possible configuration files accepted by oslo.config
   40 
   41     This also includes the deprecated ones
   42     """
   43     # default files
   44     conf_files = cfg.find_config_files(project='monasca',
   45                                        prog='monasca-log-api')
   46     # deprecated config files (only used if standard config files are not there)
   47     if len(conf_files) == 0:
   48         old_conf_files = cfg.find_config_files(project='monasca',
   49                                                prog='log-api')
   50         if len(old_conf_files) > 0:
   51             LOG.warning('Found deprecated old location "{}" '
   52                         'of main configuration file'.format(old_conf_files))
   53             conf_files += old_conf_files
   54     return conf_files
   55 
   56 
   57 def parse_args(argv=None):
   58     global _CONF_LOADED
   59     if _CONF_LOADED:
   60         LOG.debug('Configuration has been already loaded')
   61         return
   62 
   63     log.set_defaults()
   64     log.register_options(CONF)
   65 
   66     argv = (argv if argv is not None else sys.argv[1:])
   67     args = ([] if _is_running_under_gunicorn() else argv or [])
   68 
   69     CONF(args=args,
   70          prog=sys.argv[1:],
   71          project='monasca',
   72          version=version.version_str,
   73          default_config_files=get_config_files(),
   74          description='RESTful API to collect log files')
   75 
   76     log.setup(CONF,
   77               product_name='monasca-log-api',
   78               version=version.version_str)
   79 
   80     conf.register_opts()
   81     policy_opts.set_defaults(CONF)
   82 
   83     _CONF_LOADED = True