Confd IPv6 support
[ganeti-local] / lib / daemon.py
index 2027a4b..1fd1b74 100644 (file)
@@ -39,6 +39,7 @@ import sys
 from ganeti import utils
 from ganeti import constants
 from ganeti import errors
+from ganeti import netutils
 
 
 _DEFAULT_RUN_USER = "root"
@@ -156,7 +157,7 @@ class AsyncStreamServer(GanetiBaseAsyncoreDispatcher):
       if self.family == socket.AF_UNIX:
         # override the client address, as for unix sockets nothing meaningful
         # is passed in from accept anyway
-        client_address = utils.GetSocketCredentials(connected_socket)
+        client_address = netutils.GetSocketCredentials(connected_socket)
       logging.info("Accepted connection from %s",
                    FormatAddress(self.family, client_address))
       self.handle_connection(connected_socket, client_address)
@@ -309,13 +310,14 @@ class AsyncUDPSocket(GanetiBaseAsyncoreDispatcher):
   """An improved asyncore udp socket.
 
   """
-  def __init__(self):
+  def __init__(self, family):
     """Constructor for AsyncUDPSocket
 
     """
     GanetiBaseAsyncoreDispatcher.__init__(self)
     self._out_queue = []
-    self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
+    self._family = family
+    self.create_socket(family, socket.SOCK_DGRAM)
 
   # this method is overriding an asyncore.dispatcher method
   def handle_connect(self):
@@ -330,7 +332,12 @@ class AsyncUDPSocket(GanetiBaseAsyncoreDispatcher):
                                       constants.MAX_UDP_DATA_SIZE)
     if recv_result is not None:
       payload, address = recv_result
-      ip, port = address
+      if self._family == socket.AF_INET6:
+        # we ignore 'flow info' and 'scope id' as we don't need them
+        ip, port, _, _ = address
+      else:
+        ip, port = address
+
       self.handle_datagram(payload, ip, port)
 
   def handle_datagram(self, payload, ip, port):
@@ -551,8 +558,8 @@ def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn,
                           choices=["no", "yes", "only"])
 
   if daemon_name in constants.DAEMONS_PORTS:
-    default_bind_address = "0.0.0.0"
-    default_port = utils.GetDaemonPort(daemon_name)
+    default_bind_address = constants.IP4_ADDRESS_ANY
+    default_port = netutils.GetDaemonPort(daemon_name)
 
     # For networked daemons we allow choosing the port and bind address
     optionparser.add_option("-p", "--port", dest="port",