d3594c4b81b5b2fdf86f55d1ea1bb9ec27f1af40
[openstack-build/neutron-build.git] / neutron / agent / common / config.py
1 # Copyright 2012 OpenStack Foundation
2 # All Rights Reserved.
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 os
17
18 from oslo_config import cfg
19
20 from neutron._i18n import _
21 from neutron.common import config
22
23
24 ROOT_HELPER_OPTS = [
25     cfg.StrOpt('root_helper', default='sudo',
26                help=_("Root helper application. "
27                       "Use 'sudo neutron-rootwrap /etc/neutron/rootwrap.conf' "
28                       "to use the real root filter facility. Change to 'sudo' "
29                       "to skip the filtering and just run the command "
30                       "directly.")),
31     cfg.BoolOpt('use_helper_for_ns_read',
32                 default=True,
33                 help=_("Use the root helper when listing the namespaces on a "
34                        "system. This may not be required depending on the "
35                        "security configuration. If the root helper is "
36                        "not required, set this to False for a performance "
37                        "improvement.")),
38     # We can't just use root_helper=sudo neutron-rootwrap-daemon $cfg because
39     # it isn't appropriate for long-lived processes spawned with create_process
40     # Having a bool use_rootwrap_daemon option precludes specifying the
41     # rootwrap daemon command, which may be necessary for Xen?
42     cfg.StrOpt('root_helper_daemon',
43                help=_('Root helper daemon application to use when possible.')),
44 ]
45
46 AGENT_STATE_OPTS = [
47     cfg.FloatOpt('report_interval', default=30,
48                  help=_('Seconds between nodes reporting state to server; '
49                         'should be less than agent_down_time, best if it '
50                         'is half or less than agent_down_time.')),
51     cfg.BoolOpt('log_agent_heartbeats', default=False,
52                 help=_('Log agent heartbeats')),
53 ]
54
55 INTERFACE_DRIVER_OPTS = [
56     cfg.StrOpt('interface_driver',
57                help=_("The driver used to manage the virtual interface.")),
58 ]
59
60 IPTABLES_OPTS = [
61     cfg.BoolOpt('comment_iptables_rules', default=True,
62                 help=_("Add comments to iptables rules. "
63                        "Set to false to disallow the addition of comments to "
64                        "generated iptables rules that describe each rule's "
65                        "purpose. System must support the iptables comments "
66                        "module for addition of comments.")),
67 ]
68
69 PROCESS_MONITOR_OPTS = [
70     cfg.StrOpt('check_child_processes_action', default='respawn',
71                choices=['respawn', 'exit'],
72                help=_('Action to be executed when a child process dies')),
73     cfg.IntOpt('check_child_processes_interval', default=60,
74                help=_('Interval between checks of child process liveness '
75                       '(seconds), use 0 to disable')),
76 ]
77
78 AVAILABILITY_ZONE_OPTS = [
79     # The default AZ name "nova" is selected to match the default
80     # AZ name in Nova and Cinder.
81     cfg.StrOpt('availability_zone', max_length=255, default='nova',
82                help=_("Availability zone of this node")),
83 ]
84
85 EXT_NET_BRIDGE_OPTS = [
86     cfg.StrOpt('external_network_bridge', default='br-ex',
87                deprecated_for_removal=True,
88                help=_("Name of bridge used for external network "
89                       "traffic. This should be set to an empty value for the "
90                       "Linux Bridge. When this parameter is set, each L3 "
91                       "agent can be associated with no more than one external "
92                       "network. This option is deprecated and will be removed "
93                       "in the M release.")),
94 ]
95
96
97 def get_log_args(conf, log_file_name, **kwargs):
98     cmd_args = []
99     if conf.debug:
100         cmd_args.append('--debug')
101     if conf.verbose:
102         cmd_args.append('--verbose')
103     if (conf.log_dir or conf.log_file):
104         cmd_args.append('--log-file=%s' % log_file_name)
105         log_dir = None
106         if conf.log_dir and conf.log_file:
107             log_dir = os.path.dirname(
108                 os.path.join(conf.log_dir, conf.log_file))
109         elif conf.log_dir:
110             log_dir = conf.log_dir
111         elif conf.log_file:
112             log_dir = os.path.dirname(conf.log_file)
113         if log_dir:
114             cmd_args.append('--log-dir=%s' % log_dir)
115         if kwargs.get('metadata_proxy_watch_log') is False:
116             cmd_args.append('--nometadata_proxy_watch_log')
117     else:
118         if conf.use_syslog:
119             cmd_args.append('--use-syslog')
120             if conf.syslog_log_facility:
121                 cmd_args.append(
122                     '--syslog-log-facility=%s' % conf.syslog_log_facility)
123     return cmd_args
124
125
126 def register_root_helper(conf):
127     conf.register_opts(ROOT_HELPER_OPTS, 'AGENT')
128
129
130 def register_agent_state_opts_helper(conf):
131     conf.register_opts(AGENT_STATE_OPTS, 'AGENT')
132
133
134 def register_interface_driver_opts_helper(conf):
135     conf.register_opts(INTERFACE_DRIVER_OPTS)
136
137
138 def register_iptables_opts(conf):
139     conf.register_opts(IPTABLES_OPTS, 'AGENT')
140
141
142 def register_process_monitor_opts(conf):
143     conf.register_opts(PROCESS_MONITOR_OPTS, 'AGENT')
144
145
146 def register_availability_zone_opts_helper(conf):
147     conf.register_opts(AVAILABILITY_ZONE_OPTS, 'AGENT')
148
149
150 def get_root_helper(conf):
151     return conf.AGENT.root_helper
152
153
154 def setup_conf():
155     bind_opts = [
156         cfg.StrOpt('state_path',
157                    default='/var/lib/neutron',
158                    help=_("Where to store Neutron state files. "
159                           "This directory must be writable by the agent.")),
160     ]
161
162     conf = cfg.ConfigOpts()
163     conf.register_opts(bind_opts)
164     return conf
165
166 # add a logging setup method here for convenience
167 setup_logging = config.setup_logging