Revision a5bc662a

b/lib/constants.py
91 91
INISECT_INS = "instance"
92 92

  
93 93
# common exit codes
94
EXIT_SUCCESS = 0
94 95
EXIT_NOTMASTER = 11
95 96
EXIT_NODESETUP_ERROR = 12
97
EXIT_CONFIRMATION = 13 # need user confirmation
96 98

  
97 99
# tags
98 100
TAG_CLUSTER = "cluster"
b/man/gnt-node.sgml
126 126
    </refsect2>
127 127

  
128 128
    <refsect2>
129
      <title>EVACUATE</title>
130

  
131
      <cmdsynopsis>
132
        <command>evacuate</command>
133
        <arg>-f</arg>
134
        <arg choice="req"><replaceable>source_node</replaceable></arg>
135
        <arg choice="req"><replaceable>destination_node</replaceable></arg>
136
      </cmdsynopsis>
137

  
138
      <para>
139
        This command will change the secondary node from the source
140
        node to the destination node for all instances having the
141
        source node as secondary. It works only for instances having
142
        a remote raid disk layout.
143
      </para>
144

  
145
      <para>
146
        Example:
147
        <screen>
148
          # gnt-node evacuate node1.example.com node2.example.com
149
        </screen>
150
      </para>
151
    </refsect2>
152

  
153
    <refsect2>
129 154
      <title>FAILOVER</title>
130 155

  
131 156
      <cmdsynopsis>
b/scripts/gnt-node
94 94
  return 0
95 95

  
96 96

  
97
def EvacuateNode(opts, args):
98
  """Relocate all secondary instance from a node.
99

  
100
  """
101
  force = opts.force
102
  selected_fields = ["name", "sinst_list"]
103
  src_node, dst_node = args
104

  
105
  op = opcodes.OpQueryNodes(output_fields=selected_fields, names=[src_node])
106
  result = SubmitOpCode(op)
107
  src_node, sinst = result[0]
108
  op = opcodes.OpQueryNodes(output_fields=["name"], names=[dst_node])
109
  result = SubmitOpCode(op)
110
  dst_node = result[0][0]
111

  
112
  if src_node == dst_node:
113
    raise errors.OpPrereqError("Evacuate node needs different source and"
114
                               " target nodes (node %s given twice)" %
115
                               src_node)
116

  
117
  if not sinst:
118
    logger.ToStderr("No secondary instances on node %s, exiting." % src_node)
119
    return constants.EXIT_SUCCESS
120

  
121
  sinst = utils.NiceSort(sinst)
122

  
123
  retcode = constants.EXIT_SUCCESS
124

  
125
  if not force and not AskUser("Relocate instance(s) %s from node\n"
126
                               " %s to node\n %s?" %
127
                               (",".join("'%s'" % name for name in sinst),
128
                               src_node, dst_node)):
129
    return constants.EXIT_CONFIRMATION
130

  
131
  good_cnt = bad_cnt = 0
132
  for iname in sinst:
133
    op = opcodes.OpReplaceDisks(instance_name=iname,
134
                                remote_node=dst_node)
135
    try:
136
      logger.ToStdout("Replacing disks for instance %s" % iname)
137
      SubmitOpCode(op)
138
      logger.ToStdout("Instance %s has been relocated" % iname)
139
      good_cnt += 1
140
    except errors.GenericError, err:
141
      nret, msg = FormatError(err)
142
      retcode |= nret
143
      logger.ToStderr("Error replacing disks for instance %s: %s" %
144
                      (iname, msg))
145
      bad_cnt += 1
146

  
147
  if retcode == constants.EXIT_SUCCESS:
148
    logger.ToStdout("All %d instance(s) relocated successfully." % good_cnt)
149
  else:
150
    logger.ToStdout("There were errors during the relocation:\n"
151
                    "%d error(s) out of %d instance(s)." %
152
                    (bad_cnt, good_cnt + bad_cnt))
153
  return retcode
154

  
155

  
97 156
def FailoverNode(opts, args):
98 157
  """Failover all primary instance on a node.
99 158

  
......
220 279
                       help="Specify the secondary ip for the node",
221 280
                       metavar="ADDRESS", default=None),],
222 281
          "<node_name>", "Add a node to the cluster"),
282
  'evacuate': (EvacuateNode, ARGS_FIXED(2),
283
               [DEBUG_OPT, FORCE_OPT],
284
               "[-f] <src_node> <dst_node>",
285
               "Relocate the secondary instances from the first node"
286
               " to the second one (only for instances of type remote_raid1)"),
223 287
  'failover': (FailoverNode, ARGS_ONE,
224 288
               [DEBUG_OPT, FORCE_OPT,
225 289
                make_option("--ignore-consistency", dest="ignore_consistency",

Also available in: Unified diff