From f4d4e184dc02a64fe8b588fff9c1e8228c9017be Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 12 Dec 2007 13:13:27 +0000
Subject: [PATCH] =?UTF-8?q?Add=20the=20=E2=80=98gnt-cluster=20verify-disks?=
 =?UTF-8?q?=E2=80=99=20command?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch adds the OpVerifyDisks handling in mcpu.py and the
verify-disks command in the gnt-cluster script, which for every instance
computed by LUVerifyDisks submits a new OpActivateInstanceDisks request.

Reviewed-by: imsnah
---
 lib/mcpu.py         |  1 +
 scripts/gnt-cluster | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/lib/mcpu.py b/lib/mcpu.py
index 26512bc88..4ba5926b9 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -51,6 +51,7 @@ class Processor(object):
     opcodes.OpMasterFailover: cmdlib.LUMasterFailover,
     opcodes.OpDumpClusterConfig: cmdlib.LUDumpClusterConfig,
     opcodes.OpRenameCluster: cmdlib.LURenameCluster,
+    opcodes.OpVerifyDisks: cmdlib.LUVerifyDisks,
     # node lu
     opcodes.OpAddNode: cmdlib.LUAddNode,
     opcodes.OpQueryNodes: cmdlib.LUQueryNodes,
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index d96f58c69..424b239d7 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -26,6 +26,7 @@ import pprint
 from ganeti.cli import *
 from ganeti import opcodes
 from ganeti import constants
+from ganeti import errors
 
 
 def InitCluster(opts, args):
@@ -181,6 +182,39 @@ def VerifyCluster(opts, args):
   return result
 
 
+def VerifyDisks(opts, args):
+  """Verify integrity of cluster disks.
+
+  Args:
+    opts - class with options as members
+
+  """
+  op = opcodes.OpVerifyDisks()
+  result = SubmitOpCode(op)
+  if not isinstance(result, tuple) or len(result) != 2:
+    raise errors.ProgrammerError("Unknown result type for OpVerifyDisks")
+
+  nodes, instances = result
+  if nodes:
+    print "Nodes unreachable or with bad data:"
+    for name in nodes:
+      print "\t%s" % name
+  retcode = constants.EXIT_SUCCESS
+  if instances:
+    for iname in instances:
+      op = opcodes.OpActivateInstanceDisks(instance_name=iname)
+      try:
+        print "Activating disks for instance '%s'" % iname
+        SubmitOpCode(op)
+      except errors.GenericError, err:
+        nret, msg = FormatError(err)
+        retcode |= nret
+        print >>sys.stderr, ("Error activating disks for instance %s: %s" %
+                             (iname, msg))
+
+  return retcode
+
+
 def MasterFailover(opts, args):
   """Failover the master node.
 
@@ -263,6 +297,8 @@ commands = {
                "Renames the cluster"),
   'verify': (VerifyCluster, ARGS_NONE, [DEBUG_OPT],
              "", "Does a check on the cluster configuration"),
+  'verify-disks': (VerifyDisks, ARGS_NONE, [DEBUG_OPT],
+                   "", "Does a check on the cluster disk status"),
   'masterfailover': (MasterFailover, ARGS_NONE, [DEBUG_OPT],
                      "", "Makes the current node the master"),
   'version': (ShowClusterVersion, ARGS_NONE, [DEBUG_OPT],
-- 
GitLab