Code and docstring style fixes
[ganeti-local] / lib / cli.py
index c7f23a1..292cab0 100644 (file)
@@ -25,7 +25,6 @@
 import sys
 import textwrap
 import os.path
 import sys
 import textwrap
 import os.path
-import copy
 import time
 import logging
 from cStringIO import StringIO
 import time
 import logging
 from cStringIO import StringIO
@@ -62,6 +61,8 @@ __all__ = [
   "FIELDS_OPT",
   "FILESTORE_DIR_OPT",
   "FILESTORE_DRIVER_OPT",
   "FIELDS_OPT",
   "FILESTORE_DIR_OPT",
   "FILESTORE_DRIVER_OPT",
+  "FORCE_OPT",
+  "FORCE_VARIANT_OPT",
   "GLOBAL_FILEDIR_OPT",
   "HVLIST_OPT",
   "HVOPTS_OPT",
   "GLOBAL_FILEDIR_OPT",
   "HVLIST_OPT",
   "HVOPTS_OPT",
@@ -71,7 +72,6 @@ __all__ = [
   "IGNORE_FAILURES_OPT",
   "IGNORE_SECONDARIES_OPT",
   "IGNORE_SIZE_OPT",
   "IGNORE_FAILURES_OPT",
   "IGNORE_SECONDARIES_OPT",
   "IGNORE_SIZE_OPT",
-  "FORCE_OPT",
   "MAC_PREFIX_OPT",
   "MASTER_NETDEV_OPT",
   "MC_OPT",
   "MAC_PREFIX_OPT",
   "MASTER_NETDEV_OPT",
   "MC_OPT",
@@ -110,6 +110,7 @@ __all__ = [
   "STATIC_OPT",
   "SYNC_OPT",
   "TAG_SRC_OPT",
   "STATIC_OPT",
   "SYNC_OPT",
   "TAG_SRC_OPT",
+  "TIMEOUT_OPT",
   "USEUNITS_OPT",
   "VERBOSE_OPT",
   "VG_NAME_OPT",
   "USEUNITS_OPT",
   "VERBOSE_OPT",
   "VG_NAME_OPT",
@@ -158,6 +159,7 @@ __all__ = [
   "OPT_COMPL_ONE_OS",
   "cli_option",
   "SplitNodeOption",
   "OPT_COMPL_ONE_OS",
   "cli_option",
   "SplitNodeOption",
+  "CalculateOSNames",
   ]
 
 NO_PREFIX = "no_"
   ]
 
 NO_PREFIX = "no_"
@@ -566,6 +568,10 @@ OS_OPT = cli_option("-o", "--os-type", dest="os", help="What OS to run",
                     metavar="<os>",
                     completion_suggest=OPT_COMPL_ONE_OS)
 
                     metavar="<os>",
                     completion_suggest=OPT_COMPL_ONE_OS)
 
+FORCE_VARIANT_OPT = cli_option("--force-variant", dest="force_variant",
+                               action="store_true", default=False,
+                               help="Force an unknown variant")
+
 BACKEND_OPT = cli_option("-B", "--backend-parameters", dest="beparams",
                          type="keyval", default={},
                          help="Backend parameters")
 BACKEND_OPT = cli_option("-B", "--backend-parameters", dest="beparams",
                          type="keyval", default={},
                          help="Backend parameters")
@@ -806,10 +812,13 @@ IGNORE_SECONDARIES_OPT = cli_option("--ignore-secondaries",
                                     default=False, action="store_true",
                                     help="Ignore errors from secondaries")
 
                                     default=False, action="store_true",
                                     help="Ignore errors from secondaries")
 
-NOSHUTDOWN_OPT = cli_option("","--noshutdown", dest="shutdown",
+NOSHUTDOWN_OPT = cli_option("--noshutdown", dest="shutdown",
                             action="store_false", default=True,
                             help="Don't shutdown the instance (unsafe)")
 
                             action="store_false", default=True,
                             help="Don't shutdown the instance (unsafe)")
 
+TIMEOUT_OPT = cli_option("--timeout", dest="timeout", type="int",
+                         default=constants.DEFAULT_SHUTDOWN_TIMEOUT,
+                         help="Maximum time to wait")
 
 
 def _ParseArgs(argv, commands, aliases):
 
 
 def _ParseArgs(argv, commands, aliases):
@@ -971,6 +980,23 @@ def SplitNodeOption(value):
     return (value, None)
 
 
     return (value, None)
 
 
+def CalculateOSNames(os_name, os_variants):
+  """Calculates all the names an OS can be called, according to its variants.
+
+  @type os_name: string
+  @param os_name: base name of the os
+  @type os_variants: list or None
+  @param os_variants: list of supported variants
+  @rtype: list
+  @return: list of valid names
+
+  """
+  if os_variants:
+    return ['%s+%s' % (os_name, v) for v in os_variants]
+  else:
+    return [os_name]
+
+
 def UsesRPC(fn):
   def wrapper(*args, **kwargs):
     rpc.Init()
 def UsesRPC(fn):
   def wrapper(*args, **kwargs):
     rpc.Init()
@@ -1527,7 +1553,7 @@ def GenerateTable(headers, fields, separator, data,
     args = []
     if line is None:
       line = ['-' for _ in fields]
     args = []
     if line is None:
       line = ['-' for _ in fields]
-    for idx in xrange(len(fields)):
+    for idx in range(len(fields)):
       if separator is None:
         args.append(mlens[idx])
       args.append(line[idx])
       if separator is None:
         args.append(mlens[idx])
       args.append(line[idx])