From 9769bb7828062eb3cf1115889012f740fd9da910 Mon Sep 17 00:00:00 2001
From: Manuel Franceschini <livewire@google.com>
Date: Thu, 24 Jun 2010 11:01:38 +0200
Subject: [PATCH] Rename some constants to facilitate IPv6 support

Signed-off-by: Manuel Franceschini <livewire@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 daemons/ganeti-watcher          |  4 ++--
 lib/backend.py                  |  2 +-
 lib/constants.py                |  8 ++++----
 lib/utils.py                    |  2 +-
 scripts/gnt-instance            |  2 +-
 test/ganeti.backend_unittest.py |  2 +-
 test/ganeti.config_unittest.py  |  2 +-
 test/ganeti.utils_unittest.py   | 24 ++++++++++++------------
 8 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher
index b0d924d43..e5ce91370 100755
--- a/daemons/ganeti-watcher
+++ b/daemons/ganeti-watcher
@@ -701,13 +701,13 @@ def main():
 
       # If RAPI isn't responding to queries, try one restart.
       logging.debug("Attempting to talk with RAPI.")
-      if not IsRapiResponding(constants.LOCALHOST_IP_ADDRESS):
+      if not IsRapiResponding(constants.IP4_ADDRESS_LOCALHOST):
         logging.warning("Couldn't get answer from Ganeti RAPI daemon."
                         " Restarting Ganeti RAPI.")
         utils.StopDaemon(constants.RAPI)
         utils.EnsureDaemon(constants.RAPI)
         logging.debug("Second attempt to talk with RAPI")
-        if not IsRapiResponding(constants.LOCALHOST_IP_ADDRESS):
+        if not IsRapiResponding(constants.IP4_ADDRESS_LOCALHOST):
           logging.fatal("RAPI is not responding. Please investigate.")
       logging.debug("Successfully talked to RAPI.")
 
diff --git a/lib/backend.py b/lib/backend.py
index dca969278..0e3c2e244 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -539,7 +539,7 @@ def VerifyNode(what, cluster_name):
     # rest of the function)
     master_name, master_ip = what[constants.NV_MASTERIP]
     if master_name == my_name:
-      source = constants.LOCALHOST_IP_ADDRESS
+      source = constants.IP4_ADDRESS_LOCALHOST
     else:
       source = None
     result[constants.NV_MASTERIP] = utils.TcpPing(master_ip, port,
diff --git a/lib/constants.py b/lib/constants.py
index b7cda08d9..e68d0d22b 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -434,11 +434,11 @@ MAX_TAGS_PER_OBJ = 4096
 # others
 DEFAULT_BRIDGE = "xen-br0"
 SYNC_SPEED = 60 * 1024
-LOCALHOST_IP_ADDRESS = "127.0.0.1"
+IP4_ADDRESS_LOCALHOST = "127.0.0.1"
+IP4_ADDRESS_ANY = "0.0.0.0"
 TCP_PING_TIMEOUT = 10
 GANETI_RUNAS = "root"
 DEFAULT_VG = "xenvg"
-BIND_ADDRESS_GLOBAL = "0.0.0.0"
 MIN_VG_SIZE = 20480
 DEFAULT_MAC_PREFIX = "aa:00:00"
 LVM_STRIPECOUNT = _autoconf.LVM_STRIPECOUNT
@@ -635,7 +635,7 @@ HTS_REQ_PORT = frozenset([HT_XEN_HVM, HT_KVM])
 
 VNC_BASE_PORT = 5900
 VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
-VNC_DEFAULT_BIND_ADDRESS = '0.0.0.0'
+VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY 
 
 # NIC types
 HT_NIC_RTL8139 = "rtl8139"
@@ -833,7 +833,7 @@ HVC_DEFAULTS = {
     HV_CDROM_IMAGE_PATH: '',
     HV_NIC_TYPE: HT_NIC_RTL8139,
     HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
-    HV_VNC_BIND_ADDRESS: '0.0.0.0',
+    HV_VNC_BIND_ADDRESS: IP4_ADDRESS_ANY,
     HV_VNC_PASSWORD_FILE: VNC_PASSWORD_FILE,
     HV_ACPI: True,
     HV_PAE: True,
diff --git a/lib/utils.py b/lib/utils.py
index 1fdc581b1..ebbde5770 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1740,7 +1740,7 @@ def OwnIpAddress(address):
 
   """
   return TcpPing(address, constants.DEFAULT_NODED_PORT,
-                 source=constants.LOCALHOST_IP_ADDRESS)
+                 source=constants.IP4_ADDRESS_LOCALHOST)
 
 
 def ListVisibleFiles(path):
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index c0230d91c..521be301e 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -1187,7 +1187,7 @@ def ShowInstanceConfig(opts, args):
     if vnc_bind_address:
       port = instance["network_port"]
       display = int(port) - constants.VNC_BASE_PORT
-      if display > 0 and vnc_bind_address == constants.BIND_ADDRESS_GLOBAL:
+      if display > 0 and vnc_bind_address == constants.IP4_ADDRESS_ANY:
         vnc_console_port = "%s:%s (display %s)" % (instance["pnode"],
                                                    port,
                                                    display)
diff --git a/test/ganeti.backend_unittest.py b/test/ganeti.backend_unittest.py
index 756aed977..efef4efdb 100755
--- a/test/ganeti.backend_unittest.py
+++ b/test/ganeti.backend_unittest.py
@@ -73,7 +73,7 @@ class TestX509Certificates(unittest.TestCase):
 class TestNodeVerify(testutils.GanetiTestCase):
   def testMasterIPLocalhost(self):
     # this a real functional test, but requires localhost to be reachable
-    local_data = (utils.HostInfo().name, constants.LOCALHOST_IP_ADDRESS)
+    local_data = (utils.HostInfo().name, constants.IP4_ADDRESS_LOCALHOST)
     result = backend.VerifyNode({constants.NV_MASTERIP: local_data}, None)
     self.failUnless(constants.NV_MASTERIP in result,
                     "Master IP data not returned")
diff --git a/test/ganeti.config_unittest.py b/test/ganeti.config_unittest.py
index a57a3b709..6f3b0654f 100755
--- a/test/ganeti.config_unittest.py
+++ b/test/ganeti.config_unittest.py
@@ -60,7 +60,7 @@ class TestConfigRunner(unittest.TestCase):
   def _init_cluster(self, cfg):
     """Initializes the cfg object"""
     me = utils.HostInfo()
-    ip = constants.LOCALHOST_IP_ADDRESS
+    ip = constants.IP4_ADDRESS_LOCALHOST
 
     cluster_config = objects.Cluster(
       serial_no=1,
diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py
index 477c40993..25aec38c2 100755
--- a/test/ganeti.utils_unittest.py
+++ b/test/ganeti.utils_unittest.py
@@ -1169,7 +1169,7 @@ class TestTcpPing(unittest.TestCase):
 
   def setUp(self):
     self.listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    self.listener.bind((constants.LOCALHOST_IP_ADDRESS, 0))
+    self.listener.bind((constants.IP4_ADDRESS_LOCALHOST, 0))
     self.listenerport = self.listener.getsockname()[1]
     self.listener.listen(1)
 
@@ -1179,15 +1179,15 @@ class TestTcpPing(unittest.TestCase):
     del self.listenerport
 
   def testTcpPingToLocalHostAccept(self):
-    self.assert_(TcpPing(constants.LOCALHOST_IP_ADDRESS,
+    self.assert_(TcpPing(constants.IP4_ADDRESS_LOCALHOST,
                          self.listenerport,
                          timeout=10,
                          live_port_needed=True,
-                         source=constants.LOCALHOST_IP_ADDRESS,
+                         source=constants.IP4_ADDRESS_LOCALHOST,
                          ),
                  "failed to connect to test listener")
 
-    self.assert_(TcpPing(constants.LOCALHOST_IP_ADDRESS,
+    self.assert_(TcpPing(constants.IP4_ADDRESS_LOCALHOST,
                          self.listenerport,
                          timeout=10,
                          live_port_needed=True,
@@ -1200,7 +1200,7 @@ class TestTcpPingDeaf(unittest.TestCase):
 
   def setUp(self):
     self.deaflistener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    self.deaflistener.bind((constants.LOCALHOST_IP_ADDRESS, 0))
+    self.deaflistener.bind((constants.IP4_ADDRESS_LOCALHOST, 0))
     self.deaflistenerport = self.deaflistener.getsockname()[1]
 
   def tearDown(self):
@@ -1208,15 +1208,15 @@ class TestTcpPingDeaf(unittest.TestCase):
     del self.deaflistenerport
 
   def testTcpPingToLocalHostAcceptDeaf(self):
-    self.failIf(TcpPing(constants.LOCALHOST_IP_ADDRESS,
+    self.failIf(TcpPing(constants.IP4_ADDRESS_LOCALHOST,
                         self.deaflistenerport,
                         timeout=constants.TCP_PING_TIMEOUT,
                         live_port_needed=True,
-                        source=constants.LOCALHOST_IP_ADDRESS,
+                        source=constants.IP4_ADDRESS_LOCALHOST,
                         ), # need successful connect(2)
                 "successfully connected to deaf listener")
 
-    self.failIf(TcpPing(constants.LOCALHOST_IP_ADDRESS,
+    self.failIf(TcpPing(constants.IP4_ADDRESS_LOCALHOST,
                         self.deaflistenerport,
                         timeout=constants.TCP_PING_TIMEOUT,
                         live_port_needed=True,
@@ -1224,15 +1224,15 @@ class TestTcpPingDeaf(unittest.TestCase):
                 "successfully connected to deaf listener (no source addr)")
 
   def testTcpPingToLocalHostNoAccept(self):
-    self.assert_(TcpPing(constants.LOCALHOST_IP_ADDRESS,
+    self.assert_(TcpPing(constants.IP4_ADDRESS_LOCALHOST,
                          self.deaflistenerport,
                          timeout=constants.TCP_PING_TIMEOUT,
                          live_port_needed=False,
-                         source=constants.LOCALHOST_IP_ADDRESS,
+                         source=constants.IP4_ADDRESS_LOCALHOST,
                          ), # ECONNREFUSED is OK
                  "failed to ping alive host on deaf port")
 
-    self.assert_(TcpPing(constants.LOCALHOST_IP_ADDRESS,
+    self.assert_(TcpPing(constants.IP4_ADDRESS_LOCALHOST,
                          self.deaflistenerport,
                          timeout=constants.TCP_PING_TIMEOUT,
                          live_port_needed=False,
@@ -1245,7 +1245,7 @@ class TestOwnIpAddress(unittest.TestCase):
 
   def testOwnLoopback(self):
     """check having the loopback ip"""
-    self.failUnless(OwnIpAddress(constants.LOCALHOST_IP_ADDRESS),
+    self.failUnless(OwnIpAddress(constants.IP4_ADDRESS_LOCALHOST),
                     "Should own the loopback address")
 
   def testNowOwnAddress(self):
-- 
GitLab