objects: add configuration upgrade system
[ganeti-local] / scripts / gnt-os
index e4041c7..a0c09a7 100755 (executable)
 # 02110-1301, USA.
 
 
+# pylint: disable-msg=W0401,W0614
+# W0401: Wildcard import ganeti.cli
+# W0614: Unused import %s from wildcard import (since we need cli)
+
 import sys
 from optparse import make_option
 
 from ganeti.cli import *
 from ganeti import opcodes
-from ganeti import logger
-from ganeti import objects
 from ganeti import utils
-from ganeti import errors
 from ganeti import constants
 
 
 def ListOS(opts, args):
-  """List the OSes existing on this node.
+  """List the valid OSes in the cluster.
+
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: should be an empty list
+  @rtype: int
+  @return: the desired exit code
 
   """
   op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
   result = SubmitOpCode(op)
 
   if not result:
-    logger.ToStdout("Can't get the OS list")
+    ToStderr("Can't get the OS list")
     return 1
 
   if not opts.no_headers:
@@ -48,10 +55,11 @@ def ListOS(opts, args):
     headers = None
 
   data = GenerateTable(separator=None, headers=headers, fields=["name"],
-                       data=[[row[0]] for row in result if row[1]])
+                       data=[[row[0]] for row in result if row[1]],
+                       units=None)
 
   for line in data:
-    logger.ToStdout(line)
+    ToStdout(line)
 
   return 0
 
@@ -59,13 +67,19 @@ def ListOS(opts, args):
 def DiagnoseOS(opts, args):
   """Analyse all OSes on this cluster.
 
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: should be an empty list
+  @rtype: int
+  @return: the desired exit code
+
   """
   op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "node_status"],
                             names=[])
   result = SubmitOpCode(op)
 
   if not result:
-    logger.ToStdout("Can't get the OS list")
+    ToStderr("Can't get the OS list")
     return 1
 
   has_bad = False
@@ -102,15 +116,14 @@ def DiagnoseOS(opts, args):
     def _OutputPerNodeOSStatus(msg_map):
       map_k = utils.NiceSort(msg_map.keys())
       for node_name in map_k:
-        logger.ToStdout("  Node: %s, status: %s" %
-                        (node_name, msg_map[node_name]))
+        ToStdout("  Node: %s, status: %s", node_name, msg_map[node_name])
         for msg in nodes_hidden[node_name]:
-          logger.ToStdout(msg)
+          ToStdout(msg)
 
-    logger.ToStdout("OS: %s [global status: %s]" % (os_name, status))
+    ToStdout("OS: %s [global status: %s]", os_name, status)
     _OutputPerNodeOSStatus(nodes_valid)
     _OutputPerNodeOSStatus(nodes_bad)
-    logger.ToStdout("")
+    ToStdout("")
 
   return int(has_bad)