Revision b1b6ea87 lib/bootstrap.py

b/lib/bootstrap.py
27 27
import os.path
28 28
import sha
29 29
import re
30
import logging
30 31

  
31 32
from ganeti import rpc
32 33
from ganeti import ssh
......
228 229

  
229 230
  ssh.WriteKnownHostsFile(cfg, ss, constants.SSH_KNOWN_HOSTS_FILE)
230 231

  
232

  
231 233
def SetupNodeDaemon(node):
232 234
  """Add a node to the cluster.
233 235

  
234
  This function must be called before the actual opcode, and will ssh to the
235
  remote node, copy the needed files, and start ganeti-noded, allowing the master
236
  to do the rest via normal rpc calls.
236
  This function must be called before the actual opcode, and will ssh
237
  to the remote node, copy the needed files, and start ganeti-noded,
238
  allowing the master to do the rest via normal rpc calls.
237 239

  
238 240
  Args:
239 241
    node: fully qualified domain name for the new node
......
278 280

  
279 281
  return 0
280 282

  
283

  
284
def MasterFailover():
285
  """Failover the master node.
286

  
287
  This checks that we are not already the master, and will cause the
288
  current master to cease being master, and the non-master to become
289
  new master.
290

  
291
  """
292
  ss = ssconf.WritableSimpleStore()
293

  
294
  new_master = utils.HostInfo().name
295
  old_master = ss.GetMasterNode()
296

  
297
  if old_master == new_master:
298
    raise errors.OpPrereqError("This commands must be run on the node"
299
                               " where you want the new master to be."
300
                               " %s is already the master" %
301
                               old_master)
302
  # end checks
303

  
304
  rcode = 0
305

  
306
  logging.info("setting master to %s, old master: %s", new_master, old_master)
307

  
308
  if not rpc.call_node_stop_master(old_master, True):
309
    logging.error("could disable the master role on the old master"
310
                 " %s, please disable manually", old_master)
311

  
312
  ss.SetKey(ss.SS_MASTER_NODE, new_master)
313

  
314
  cfg = config.ConfigWriter()
315

  
316
  if not rpc.call_upload_file(cfg.GetNodeList(),
317
                              ss.KeyToFilename(ss.SS_MASTER_NODE)):
318
    logger.Error("could not distribute the new simple store master file"
319
                 " to the other nodes, please check.")
320

  
321
  if not rpc.call_node_start_master(new_master, True):
322
    logging.error("could not start the master role on the new master"
323
                  " %s, please check", new_master)
324
    rcode = 1
325

  
326
  return rcode

Also available in: Unified diff