Digestion to ONAP
[optf/has.git] / conductor / conductor / service.py
1 #
2 # -------------------------------------------------------------------------
3 #   Copyright (c) 2015-2017 AT&T Intellectual Property
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 # -------------------------------------------------------------------------
18 #
19
20 import sys
21
22 # from keystoneauth1 import loading as ka_loading
23 from oslo_config import cfg
24 import oslo_i18n
25 from oslo_log import log
26 # from oslo_policy import opts as policy_opts
27 from oslo_reports import guru_meditation_report as gmr
28
29 from conductor.conf import defaults
30 # from conductor import keystone_client
31 from conductor import messaging
32 from conductor import version
33
34 OPTS = [
35     # cfg.StrOpt('host',
36     #            default=socket.gethostname(),
37     #            sample_default='<your_hostname>',
38     #            help='Name of this node, which must be valid in an AMQP '
39     #            'key. Can be an opaque identifier. For ZeroMQ only, must '
40     #            'be a valid host name, FQDN, or IP address.'),
41     # cfg.IntOpt('http_timeout',
42     #            default=600,
43     #            help='Timeout seconds for HTTP requests. Set it to None to '
44     #                 'disable timeout.'),
45     cfg.StrOpt('keyspace',
46                default='conductor',
47                help='Music keyspace for content'),
48     cfg.IntOpt('delay_time',
49                 default=2,
50                 help='Delay time (Seconds) for MUSIC requests. Set it to 2 seconds '
51                      'by default.'),
52     #TODO(larry): move to a new section [feature_supported] in config file
53     cfg.BoolOpt('HPA_enabled',
54                 default=True)
55 ]
56 cfg.CONF.register_opts(OPTS)
57
58 # DATA_OPT = cfg.IntOpt('workers',
59 #                       default=1,
60 #                       min=1,
61 #                       help='Number of workers for data service, '
62 #                            'default value is 1.')
63 # cfg.CONF.register_opt(DATA_OPT, 'data')
64 #
65 # PARSER_OPT = cfg.IntOpt('workers',
66 #                         default=1,
67 #                         min=1,
68 #                         help='Number of workers for parser service. '
69 #                              'default value is 1.')
70 # cfg.CONF.register_opt(PARSER_OPT, 'parser')
71 #
72 # SOLVER_OPT = cfg.IntOpt('workers',
73 #                         default=1,
74 #                         min=1,
75 #                         help='Number of workers for solver service. '
76 #                              'default value is 1.')
77 # cfg.CONF.register_opt(SOLVER_OPT, 'solver')
78
79 # keystone_client.register_keystoneauth_opts(cfg.CONF)
80
81
82 def prepare_service(argv=None, config_files=None):
83     if argv is None:
84         argv = sys.argv
85
86     # FIXME(sileht): Use ConfigOpts() instead
87     conf = cfg.CONF
88
89     oslo_i18n.enable_lazy()
90     log.register_options(conf)
91     log_levels = (conf.default_log_levels +
92                   ['futurist=INFO'])
93     log.set_defaults(default_log_levels=log_levels)
94     defaults.set_cors_middleware_defaults()
95     # policy_opts.set_defaults(conf)
96
97     conf(argv[1:], project='conductor', validate_default_values=True,
98          version=version.version_info.version_string(),
99          default_config_files=config_files)
100
101     # ka_loading.load_auth_from_conf_options(conf, "service_credentials")
102
103     log.setup(conf, 'conductor')
104     # NOTE(liusheng): guru cannot run with service under apache daemon, so when
105     # conductor-api running with mod_wsgi, the argv is [], we don't start
106     # guru.
107     if argv:
108         gmr.TextGuruMeditation.setup_autorun(version)
109     messaging.setup()
110     return conf