add python compatibility module
[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 conductor.common import sms
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     cfg.IntOpt('delay_time',
50                 default=2,
51                 help='Delay time (Seconds) for MUSIC requests. Set it to 2 seconds '
52                      'by default.'),
53     #TODO(larry): move to a new section [feature_supported] in config file
54     cfg.BoolOpt('HPA_enabled',
55                 default=True)
56 ]
57 cfg.CONF.register_opts(OPTS)
58
59 # DATA_OPT = cfg.IntOpt('workers',
60 #                       default=1,
61 #                       min=1,
62 #                       help='Number of workers for data service, '
63 #                            'default value is 1.')
64 # cfg.CONF.register_opt(DATA_OPT, 'data')
65 #
66 # PARSER_OPT = cfg.IntOpt('workers',
67 #                         default=1,
68 #                         min=1,
69 #                         help='Number of workers for parser service. '
70 #                              'default value is 1.')
71 # cfg.CONF.register_opt(PARSER_OPT, 'parser')
72 #
73 # SOLVER_OPT = cfg.IntOpt('workers',
74 #                         default=1,
75 #                         min=1,
76 #                         help='Number of workers for solver service. '
77 #                              'default value is 1.')
78 # cfg.CONF.register_opt(SOLVER_OPT, 'solver')
79
80 # keystone_client.register_keystoneauth_opts(cfg.CONF)
81
82
83 def prepare_service(argv=None, config_files=None):
84     if argv is None:
85         argv = sys.argv
86
87     # FIXME(sileht): Use ConfigOpts() instead
88     conf = cfg.CONF
89
90     oslo_i18n.enable_lazy()
91     log.register_options(conf)
92     log_levels = (conf.default_log_levels +
93                   ['futurist=INFO'])
94     log.set_defaults(default_log_levels=log_levels)
95     defaults.set_cors_middleware_defaults()
96     # policy_opts.set_defaults(conf)
97
98     conf(argv[1:], project='conductor', validate_default_values=True,
99          version=version.version_info.version_string(),
100          default_config_files=config_files)
101
102     # ka_loading.load_auth_from_conf_options(conf, "service_credentials")
103
104     log.setup(conf, 'conductor')
105     # NOTE(liusheng): guru cannot run with service under apache daemon, so when
106     # conductor-api running with mod_wsgi, the argv is [], we don't start
107     # guru.
108     if argv:
109         gmr.TextGuruMeditation.setup_autorun(version)
110     messaging.setup()
111     # Load secrets from SMS
112     if conf.aaf_sms.is_enabled:
113         sms.load_secrets()
114     return conf