Revision 702eff21

b/lib/backend.py
81 81
#: Valid LVS output line regex
82 82
_LVSLINE_REGEX = re.compile("^ *([^|]+)\|([^|]+)\|([0-9.]+)\|([^|]{6})\|?$")
83 83

  
84
# Actions for the master setup script
85
_MASTER_START = "start"
86
_MASTER_STOP = "stop"
87

  
84 88

  
85 89
class RPCFail(Exception):
86 90
  """Class denoting RPC failure.
......
303 307
  env = {
304 308
    "MASTER_NETDEV": master_params.netdev,
305 309
    "MASTER_IP": master_params.ip,
306
    "MASTER_NETMASK": master_params.netmask,
310
    "MASTER_NETMASK": str(master_params.netmask),
307 311
    "CLUSTER_IP_VERSION": str(ver),
308 312
  }
309 313

  
310 314
  return env
311 315

  
312 316

  
313
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, "master-ip-turnup",
314
               _BuildMasterIpEnv)
315
def ActivateMasterIp(master_params, use_external_mip_script):
316
  """Activate the IP address of the master daemon.
317
def _RunMasterSetupScript(master_params, action, use_external_mip_script):
318
  """Execute the master IP address setup script.
317 319

  
318 320
  @type master_params: L{objects.MasterNetworkParameters}
319 321
  @param master_params: network parameters of the master
322
  @type action: string
323
  @param action: action to pass to the script. Must be one of
324
    L{backend._MASTER_START} or L{backend._MASTER_STOP}
320 325
  @type use_external_mip_script: boolean
321 326
  @param use_external_mip_script: whether to use an external master IP
322 327
    address setup script
328
  @raise backend.RPCFail: if there are errors during the execution of the
329
    script
323 330

  
324 331
  """
325
  # pylint: disable=W0613
326
  err_msg = None
327
  if netutils.TcpPing(master_params.ip, constants.DEFAULT_NODED_PORT):
328
    if netutils.IPAddress.Own(master_params.ip):
329
      # we already have the ip:
330
      logging.debug("Master IP already configured, doing nothing")
331
    else:
332
      err_msg = "Someone else has the master ip, not activating"
333
      logging.error(err_msg)
332
  env = _BuildMasterIpEnv(master_params)
333

  
334
  if use_external_mip_script:
335
    setup_script = constants.EXTERNAL_MASTER_SETUP_SCRIPT
334 336
  else:
335
    ipcls = netutils.IPAddress.GetClassFromIpFamily(master_params.ip_family)
337
    setup_script = constants.DEFAULT_MASTER_SETUP_SCRIPT
336 338

  
337
    result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "add",
338
                           "%s/%s" % (master_params.ip, master_params.netmask),
339
                           "dev", master_params.netdev, "label",
340
                           "%s:0" % master_params.netdev])
341
    if result.failed:
342
      err_msg = "Can't activate master IP: %s" % result.output
343
      logging.error(err_msg)
339
  result = utils.RunCmd([setup_script, action], env=env, reset_env=True)
344 340

  
345
    else:
346
      # we ignore the exit code of the following cmds
347
      if ipcls == netutils.IP4Address:
348
        utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_params.netdev,
349
                      "-s", master_params.ip, master_params.ip])
350
      elif ipcls == netutils.IP6Address:
351
        try:
352
          utils.RunCmd(["ndisc6", "-q", "-r 3", master_params.ip,
353
                        master_params.netdev])
354
        except errors.OpExecError:
355
          # TODO: Better error reporting
356
          logging.warning("Can't execute ndisc6, please install if missing")
341
  if result.failed:
342
    _Fail("Failed to %s the master IP. Script return value: %s" %
343
          (action, result.exit_code), log=True)
344

  
345

  
346
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, "master-ip-turnup",
347
               _BuildMasterIpEnv)
348
def ActivateMasterIp(master_params, use_external_mip_script):
349
  """Activate the IP address of the master daemon.
357 350

  
358
  if err_msg:
359
    _Fail(err_msg)
351
  @type master_params: L{objects.MasterNetworkParameters}
352
  @param master_params: network parameters of the master
353
  @type use_external_mip_script: boolean
354
  @param use_external_mip_script: whether to use an external master IP
355
    address setup script
356
  @raise RPCFail: in case of errors during the IP startup
357

  
358
  """
359
  _RunMasterSetupScript(master_params, _MASTER_START,
360
                        use_external_mip_script)
360 361

  
361 362

  
362 363
def StartMasterDaemons(no_voting):
......
397 398
  @type use_external_mip_script: boolean
398 399
  @param use_external_mip_script: whether to use an external master IP
399 400
    address setup script
401
  @raise RPCFail: in case of errors during the IP turndown
400 402

  
401 403
  """
402
  # pylint: disable=W0613
403
  # TODO: log and report back to the caller the error failures; we
404
  # need to decide in which case we fail the RPC for this
405

  
406
  result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "del",
407
                         "%s/%s" % (master_params.ip, master_params.netmask),
408
                         "dev", master_params.netdev])
409
  if result.failed:
410
    logging.error("Can't remove the master IP, error: %s", result.output)
411
    # but otherwise ignore the failure
404
  _RunMasterSetupScript(master_params, _MASTER_STOP,
405
                        use_external_mip_script)
412 406

  
413 407

  
414 408
def StopMasterDaemons():

Also available in: Unified diff