From 92a67f4207ffecf11df5b58e689b11277f3d65cb Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Tue, 23 Dec 2014 16:17:49 +0800 Subject: [PATCH] Use get_my_ipv4 from oslo.utils Remove _get_my_ip from Cinder and replace it's usages by usages of get_my_ipv4 from netutils, because this methods implements the same functionality. Change-Id: I293128364dcd1a83e990d9c75555b04c1e4226fb --- cinder/common/config.py | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/cinder/common/config.py b/cinder/common/config.py index e3761bb28..6c5415613 100644 --- a/cinder/common/config.py +++ b/cinder/common/config.py @@ -28,32 +28,13 @@ stepping stone. import socket from oslo_config import cfg +from oslo_utils import netutils from cinder.i18n import _ CONF = cfg.CONF - -def _get_my_ip(): - """ - Returns the actual ip of the local machine. - - This code figures out what source address would be used if some traffic - were to be sent out to some well known address on the Internet. In this - case, a Google DNS server is used, but the specific address does not - matter much. No traffic is actually sent. - """ - try: - csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - csock.connect(('8.8.8.8', 80)) - (addr, _port) = csock.getsockname() - csock.close() - return addr - except socket.error: - return "127.0.0.1" - - core_opts = [ cfg.StrOpt('api_paste_config', default="api-paste.ini", @@ -71,7 +52,7 @@ CONF.register_cli_opts(debug_opts) global_opts = [ cfg.StrOpt('my_ip', - default=_get_my_ip(), + default=netutils.get_my_ipv4(), help='IP address of this host'), cfg.StrOpt('glance_host', default='$my_ip', -- 2.45.2