Some fixes to node add and re-add
authorIustin Pop <iustin@google.com>
Tue, 10 Feb 2009 16:05:24 +0000 (16:05 +0000)
committerIustin Pop <iustin@google.com>
Tue, 10 Feb 2009 16:05:24 +0000 (16:05 +0000)
The patch changes the pre-checks in node-add and re-add:
  - if the node is not already in the cluster, refuse to re-add
  - when re-adding, reuse the secondary IP from the cluster
    configuration
  - when re-adding, reset the offline and drained flags, so that RPC
    calls work (and we can actually upload the keys)

The patch also adds a missing log entry in LUSetNodeParams.

Reviewed-by: imsnah

lib/cmdlib.py
scripts/gnt-node

index 957a089..0f3e517 100644 (file)
@@ -2331,6 +2331,7 @@ class LUSetNodeParams(LogicalUnit):
 
     if self.op.drained is not None:
       node.drained = self.op.drained
+      result.append(("drained", str(self.op.drained)))
       if self.op.drained == True:
         if node.master_candidate:
           node.master_candidate = False
index 4dc73f5..ede4c60 100755 (executable)
@@ -73,31 +73,54 @@ def AddNode(opts, args):
   cl = GetClient()
   dns_data = utils.HostInfo(args[0])
   node = dns_data.name
-
-  if not opts.readd:
-    try:
-      output = cl.QueryNodes(names=[node], fields=['name'], use_locking=True)
-    except (errors.OpPrereqError, errors.OpExecError):
-      pass
-    else:
+  readd = opts.readd
+
+  try:
+    output = cl.QueryNodes(names=[node], fields=['name', 'sip'],
+                           use_locking=True)
+    node_exists, sip = output[0]
+  except (errors.OpPrereqError, errors.OpExecError):
+    node_exists = ""
+    sip = None
+
+  if readd:
+    if not node_exists:
+      ToStderr("Node %s not in the cluster"
+               " - please retry without '--readd'", node)
+      return 1
+  else:
+    if node_exists:
       ToStderr("Node %s already in the cluster (as %s)"
-               " - please use --readd", args[0], output[0][0])
+               " - please retry with '--readd'", node, node_exists)
       return 1
+    sip = opts.secondary_ip
 
   # read the cluster name from the master
   output = cl.QueryConfigValues(['cluster_name'])
   cluster_name = output[0]
 
-  ToStderr("-- WARNING -- \n"
-           "Performing this operation is going to replace the ssh daemon"
-           " keypair\n"
-           "on the target machine (%s) with the ones of the"
-           " current one\n"
-           "and grant full intra-cluster ssh root access to/from it\n", node)
+  if readd:
+    # clear the offline and drain flags on the node
+    ToStdout("Resetting the 'offline' and 'drained' flags due to re-add")
+    op = opcodes.OpSetNodeParams(node_name=node, force=True,
+                                 offline=False, drained=False)
+
+    result = SubmitOpCode(op, cl=cl)
+    if result:
+      ToStdout("Modified:")
+      for param, data in result:
+        ToStdout(" - %-5s -> %s", param, data)
+  else:
+    ToStderr("-- WARNING -- \n"
+             "Performing this operation is going to replace the ssh daemon"
+             " keypair\n"
+             "on the target machine (%s) with the ones of the"
+             " current one\n"
+             "and grant full intra-cluster ssh root access to/from it\n", node)
 
   bootstrap.SetupNodeDaemon(cluster_name, node, opts.ssh_key_check)
 
-  op = opcodes.OpAddNode(node_name=args[0], secondary_ip=opts.secondary_ip,
+  op = opcodes.OpAddNode(node_name=args[0], secondary_ip=sip,
                          readd=opts.readd)
   SubmitOpCode(op)