cmdlib: remove usage of ENABLE_FILE_STORAGE
[ganeti-local] / daemons / import-export
index 0700339..21d1d34 100755 (executable)
@@ -23,7 +23,7 @@
 
 """
 
-# pylint: disable-msg=C0103
+# pylint: disable=C0103
 # C0103: Invalid name import-export
 
 import errno
@@ -128,7 +128,7 @@ class StatusFile:
     @param port: TCP/UDP port
 
     """
-    assert isinstance(port, (int, long)) and 0 < port < 2**16
+    assert isinstance(port, (int, long)) and 0 < port < (2 ** 16)
     self._data.listen_port = port
 
   def GetListenPort(self):
@@ -200,7 +200,7 @@ class StatusFile:
 
     self._data.mtime = time.time()
     utils.WriteFile(self._path,
-                    data=serializer.DumpJson(self._data.ToDict(), indent=True),
+                    data=serializer.DumpJson(self._data.ToDict()),
                     mode=0400)
 
 
@@ -267,10 +267,16 @@ def ProcessChildIO(child, socat_stderr_read_fd, dd_stderr_read_fd,
       timeout = None
 
       if listen_timeout and not exit_timeout:
+        assert mode == constants.IEM_IMPORT and options.connect_timeout
         if status_file.GetConnected():
           listen_timeout = None
         elif listen_timeout.Remaining() < 0:
-          logging.info("Child process didn't establish connection in time")
+          errmsg = ("Child process didn't establish connection in time"
+                    " (%0.0fs), sending SIGTERM" % options.connect_timeout)
+          logging.error(errmsg)
+          status_file.AddRecentOutput(errmsg)
+          status_file.Update(True)
+
           child.Kill(signal.SIGTERM)
           exit_timeout = \
             utils.RunningTimeout(constants.CHILD_LINGER_TIMEOUT, True)
@@ -347,7 +353,7 @@ def ParseOptions():
   @return: Arguments to program
 
   """
-  global options # pylint: disable-msg=W0603
+  global options # pylint: disable=W0603
 
   parser = optparse.OptionParser(usage=("%%prog <status-file> {%s|%s}" %
                                         (constants.IEM_IMPORT,
@@ -362,6 +368,10 @@ def ParseOptions():
                     help="X509 CA file")
   parser.add_option("--bind", dest="bind", action="store", type="string",
                     help="Bind address")
+  parser.add_option("--ipv4", dest="ipv4", action="store_true",
+                    help="Use IPv4 only")
+  parser.add_option("--ipv6", dest="ipv6", action="store_true",
+                    help="Use IPv6 only")
   parser.add_option("--host", dest="host", action="store", type="string",
                     help="Remote hostname")
   parser.add_option("--port", dest="port", action="store", type="int",
@@ -401,7 +411,7 @@ def ParseOptions():
     parser.error("Invalid mode: %s" % mode)
 
   # Normalize and check parameters
-  if options.host is not None:
+  if options.host is not None and not netutils.IPAddress.IsValid(options.host):
     try:
       options.host = netutils.Hostname.GetNormalizedName(options.host)
     except errors.OpPrereqError, err:
@@ -423,6 +433,9 @@ def ParseOptions():
     parser.error("Magic must match regular expression %s" %
                  constants.IE_MAGIC_RE.pattern)
 
+  if options.ipv4 and options.ipv6:
+    parser.error("Can only use one of --ipv4 and --ipv6")
+
   return (status_file_path, mode)
 
 
@@ -528,6 +541,7 @@ def main():
                            [socat_stderr_write_fd, dd_stderr_write_fd,
                             dd_pid_write_fd, exp_size_write_fd])
       try:
+
         def _ForwardSignal(signum, _):
           """Forwards signals to child process.
 
@@ -574,7 +588,7 @@ def main():
         errmsg = "Exited with status %s" % (child.returncode, )
 
       status_file.SetExitStatus(child.returncode, errmsg)
-    except Exception, err: # pylint: disable-msg=W0703
+    except Exception, err: # pylint: disable=W0703
       logging.exception("Unhandled error occurred")
       status_file.SetExitStatus(constants.EXIT_FAILURE,
                                 "Unhandled error occurred: %s" % (err, ))