Modify gnt-node add to call external script
[ganeti-local] / daemons / import-export
index f7ebd4d..ce9c3bd 100755 (executable)
@@ -40,10 +40,12 @@ import math
 from ganeti import constants
 from ganeti import cli
 from ganeti import utils
+from ganeti import errors
 from ganeti import serializer
 from ganeti import objects
 from ganeti import locking
 from ganeti import impexpd
+from ganeti import netutils
 
 
 #: How many lines to keep in the status file
@@ -383,6 +385,8 @@ def ParseOptions():
   parser.add_option("--expected-size", dest="exp_size", action="store",
                     type="string", default=None,
                     help="Expected import/export size (MiB)")
+  parser.add_option("--magic", dest="magic", action="store",
+                    type="string", default=None, help="Magic string")
   parser.add_option("--cmd-prefix", dest="cmd_prefix", action="store",
                     type="string", help="Command prefix")
   parser.add_option("--cmd-suffix", dest="cmd_suffix", action="store",
@@ -401,6 +405,16 @@ def ParseOptions():
     # Won't return
     parser.error("Invalid mode: %s" % mode)
 
+  # Normalize and check parameters
+  if options.host is not None:
+    try:
+      options.host = netutils.Hostname.GetNormalizedName(options.host)
+    except errors.OpPrereqError, err:
+      parser.error("Invalid hostname '%s': %s" % (options.host, err))
+
+  if options.port is not None:
+    options.port = utils.ValidateServiceName(options.port)
+
   if (options.exp_size is not None and
       options.exp_size != constants.IE_CUSTOM_SIZE):
     try:
@@ -410,6 +424,10 @@ def ParseOptions():
       parser.error("Invalid value for --expected-size: %s (%s)" %
                    (options.exp_size, err))
 
+  if not (options.magic is None or constants.IE_MAGIC_RE.match(options.magic)):
+    parser.error("Magic must match regular expression %s" %
+                 constants.IE_MAGIC_RE.pattern)
+
   return (status_file_path, mode)