Added all common modules in conductor directory
[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 socket
21 import sys
22
23 # from keystoneauth1 import loading as ka_loading
24 from oslo_config import cfg
25 import oslo_i18n
26 from oslo_log import log
27 # from oslo_policy import opts as policy_opts
28 from oslo_reports import guru_meditation_report as gmr
29
30 from conductor.conf import defaults
31 # from conductor import keystone_client
32 from conductor import messaging
33 from conductor import version
34
35 OPTS = [
36     # cfg.StrOpt('host',
37     #            default=socket.gethostname(),
38     #            sample_default='<your_hostname>',
39     #            help='Name of this node, which must be valid in an AMQP '
40     #            'key. Can be an opaque identifier. For ZeroMQ only, must '
41     #            'be a valid host name, FQDN, or IP address.'),
42     # cfg.IntOpt('http_timeout',
43     #            default=600,
44     #            help='Timeout seconds for HTTP requests. Set it to None to '
45     #                 'disable timeout.'),
46     cfg.StrOpt('keyspace',
47                default='conductor',
48                help='Music keyspace for content'),
49 ]
50 cfg.CONF.register_opts(OPTS)
51
52 # DATA_OPT = cfg.IntOpt('workers',
53 #                       default=1,
54 #                       min=1,
55 #                       help='Number of workers for data service, '
56 #                            'default value is 1.')
57 # cfg.CONF.register_opt(DATA_OPT, 'data')
58 #
59 # PARSER_OPT = cfg.IntOpt('workers',
60 #                         default=1,
61 #                         min=1,
62 #                         help='Number of workers for parser service. '
63 #                              'default value is 1.')
64 # cfg.CONF.register_opt(PARSER_OPT, 'parser')
65 #
66 # SOLVER_OPT = cfg.IntOpt('workers',
67 #                         default=1,
68 #                         min=1,
69 #                         help='Number of workers for solver service. '
70 #                              'default value is 1.')
71 # cfg.CONF.register_opt(SOLVER_OPT, 'solver')
72
73 # keystone_client.register_keystoneauth_opts(cfg.CONF)
74
75
76 def prepare_service(argv=None, config_files=None):
77     if argv is None:
78         argv = sys.argv
79
80     # FIXME(sileht): Use ConfigOpts() instead
81     conf = cfg.CONF
82
83     oslo_i18n.enable_lazy()
84     log.register_options(conf)
85     log_levels = (conf.default_log_levels +
86                   ['futurist=INFO'])
87     log.set_defaults(default_log_levels=log_levels)
88     defaults.set_cors_middleware_defaults()
89     # policy_opts.set_defaults(conf)
90
91     conf(argv[1:], project='conductor', validate_default_values=True,
92          version=version.version_info.version_string(),
93          default_config_files=config_files)
94
95     # ka_loading.load_auth_from_conf_options(conf, "service_credentials")
96
97     log.setup(conf, 'conductor')
98     # NOTE(liusheng): guru cannot run with service under apache daemon, so when
99     # conductor-api running with mod_wsgi, the argv is [], we don't start
100     # guru.
101     if argv:
102         gmr.TextGuruMeditation.setup_autorun(version)
103     messaging.setup()
104     return conf