From b64fdd331e08c13550bb44a44cf70cecb65db52a Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Mon, 16 Oct 2017 13:31:00 +0700 Subject: [PATCH] Consolidate IP address configuration There are several IP address / hostname related configs (i.e. api.host_ip, docker.docker_remote_api_host, websocket_proxy.wsproxy_host) that required manual configuration by operators. Normally, these configs are default as local IP / hostname. It is undesirable for operators to tune all these configs repeatedly. Let's consolidate all these configurations into two defaults: * [DEFAULT] my_ip: The IP address which the host is using to connect to the * management network. * [DEFAULT] host: Hostname, FQDN or IP address of this host. Change-Id: Ie26578c4208a79e4306b1006c6b316a41c2b3540 Closes-Bug: #1723515 --- zun/conf/api.py | 6 ++++-- zun/conf/database.py | 5 +++-- zun/conf/docker.py | 5 +---- zun/conf/netconf.py | 33 +++++++++++++++++++++++---------- zun/conf/services.py | 16 +--------------- zun/conf/websocket_proxy.py | 2 +- zun/tests/conf_fixture.py | 2 +- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/zun/conf/api.py b/zun/conf/api.py index 1b88f4956..e149795fd 100644 --- a/zun/conf/api.py +++ b/zun/conf/api.py @@ -18,8 +18,10 @@ api_service_opts = [ default=9517, help='The port for the zun API server.'), cfg.IPOpt('host_ip', - default='127.0.0.1', - help='The listen IP for the zun API server.'), + default='$my_ip', + help="The listen IP for the zun API server. " + "The default is ``$my_ip``, " + "the IP address of this host."), cfg.BoolOpt('enable_ssl_api', default=False, help="Enable the integrated stand-alone API to service " diff --git a/zun/conf/database.py b/zun/conf/database.py index fbcf80219..bb945c4fb 100644 --- a/zun/conf/database.py +++ b/zun/conf/database.py @@ -31,9 +31,10 @@ sql_opts = [ etcd_opts = [ cfg.HostAddressOpt('etcd_host', - default='127.0.0.1', + default='$my_ip', help="Host IP address on which etcd service " - "running."), + "running. The default is ``$my_ip``, " + "the IP address of this host."), cfg.PortOpt('etcd_port', default=2379, help="Port on which etcd listen client request.") diff --git a/zun/conf/docker.py b/zun/conf/docker.py index 913125cbc..7f3a5dbc3 100644 --- a/zun/conf/docker.py +++ b/zun/conf/docker.py @@ -11,8 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import socket - from oslo_config import cfg docker_group = cfg.OptGroup(name='docker', @@ -46,8 +44,7 @@ docker_opts = [ help='Location of TLS private key file for ' 'securing docker api requests (tlskey).'), cfg.StrOpt('docker_remote_api_host', - default=socket.gethostname(), - sample_default='localhost', + default='$my_ip', help='Defines the remote api host for the docker daemon.'), cfg.StrOpt('docker_remote_api_port', default='2375', diff --git a/zun/conf/netconf.py b/zun/conf/netconf.py index 28b3702c4..ae6f561a1 100644 --- a/zun/conf/netconf.py +++ b/zun/conf/netconf.py @@ -11,13 +11,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import socket + from oslo_config import cfg from oslo_utils import netutils netconf_opts = [ - cfg.StrOpt("my_ip", + cfg.StrOpt('my_ip', default=netutils.get_my_ipv4(), + sample_default='', help=""" The IP address which the host is using to connect to the management network. @@ -27,30 +30,40 @@ Possible values: Related options: +* docker_remote_api_host +* etcd_host +* wsproxy_host +* host_ip * my_block_storage_ip +"""), + cfg.StrOpt('host', + default=socket.gethostname(), + sample_default='', + help=""" +Hostname, FQDN or IP address of this host. This can be an opaque identifier. +It is not necessarily a hostname, FQDN, or IP address. However, the node name +must be valid within an AMQP key, and if using ZeroMQ, a valid hostname, +FQDN, or IP address. + +Possible values: + +* String with hostname, FQDN or IP address. Default is hostname of this host. """), cfg.StrOpt("my_block_storage_ip", default="$my_ip", help=""" The IP address which is used to connect to the block storage network. - Possible values: - * String with valid IP address. Default is IP address of this host. - Related options: - * my_ip - if my_block_storage_ip is not set, then my_ip value is used. """), ] -ALL_OPTS = (netconf_opts) - - def register_opts(conf): - conf.register_opts(ALL_OPTS) + conf.register_opts(netconf_opts) def list_opts(): - return {"DEFAULT": ALL_OPTS} + return {'DEFAULT': netconf_opts} diff --git a/zun/conf/services.py b/zun/conf/services.py index 14c9d0be5..bbb73b79c 100644 --- a/zun/conf/services.py +++ b/zun/conf/services.py @@ -14,23 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. -import socket - from oslo_config import cfg -service_opts = [ - cfg.HostAddressOpt('host', - default=socket.gethostname(), - sample_default='localhost', - help='Name of this node. This can be an ' - 'opaque identifier. It is not necessarily ' - 'a hostname, FQDN, or IP address. ' - 'However, the node name must be valid ' - 'within an AMQP key, and if using ZeroMQ, ' - 'a valid hostname, FQDN, or IP address.'), -] - periodic_opts = [ cfg.IntOpt('periodic_interval_max', default=60, @@ -42,7 +28,7 @@ periodic_opts = [ 'seconds.'), ] -ALL_OPTS = (service_opts + periodic_opts) +ALL_OPTS = (periodic_opts) def register_opts(conf): diff --git a/zun/conf/websocket_proxy.py b/zun/conf/websocket_proxy.py index a747008aa..942c45f5b 100644 --- a/zun/conf/websocket_proxy.py +++ b/zun/conf/websocket_proxy.py @@ -38,7 +38,7 @@ Related options: * The port must be the same as ``wsproxy_port``in this section. """), cfg.StrOpt('wsproxy_host', - default='127.0.0.1', + default='$my_ip', help=""" The IP address which is used by the ``zun-wsproxy`` service to listen for incoming requests. diff --git a/zun/tests/conf_fixture.py b/zun/tests/conf_fixture.py index 514fdea02..ad91b6e35 100644 --- a/zun/tests/conf_fixture.py +++ b/zun/tests/conf_fixture.py @@ -20,7 +20,7 @@ from oslo_config import cfg from zun.common import config CONF = cfg.CONF -CONF.import_opt('host', 'zun.common.service') +CONF.import_opt('host', 'zun.conf') CONF.import_opt('connection', 'oslo_db.options', group='database') CONF.import_opt('sqlite_synchronous', 'oslo_db.options', group='database')