monasca-api  4.0.0
About: OpenStack Monasca API is a RESTful API server that is designed with a layered architecture and supports Monitoring as a Service (MONaaS).
The "Ussuri" series (maintained release).
  Fossies Dox: monasca-api-4.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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