Revision c79198a0 lib/backend.py

b/lib/backend.py
301 301

  
302 302
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, "master-ip-turnup",
303 303
               _BuildMasterIpEnv)
304
def ActivateMasterIp(master_ip, master_netmask, master_netdev, family):
304
def ActivateMasterIp(master_params):
305 305
  """Activate the IP address of the master daemon.
306 306

  
307
  @param master_ip: the master IP
308
  @param master_netmask: the master IP netmask
309
  @param master_netdev: the master network device
310
  @param family: the IP family
307
  @type master_params: L{objects.MasterNetworkParameters}
308
  @param master_params: network parameters of the master
311 309

  
312 310
  """
313 311
  err_msg = None
314
  if netutils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT):
315
    if netutils.IPAddress.Own(master_ip):
312
  if netutils.TcpPing(master_params.ip, constants.DEFAULT_NODED_PORT):
313
    if netutils.IPAddress.Own(master_params.ip):
316 314
      # we already have the ip:
317 315
      logging.debug("Master IP already configured, doing nothing")
318 316
    else:
319 317
      err_msg = "Someone else has the master ip, not activating"
320 318
      logging.error(err_msg)
321 319
  else:
322
    ipcls = netutils.IPAddress.GetClassFromIpFamily(family)
320
    ipcls = netutils.IPAddress.GetClassFromIpFamily(master_params.ip_family)
323 321

  
324 322
    result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "add",
325
                           "%s/%s" % (master_ip, master_netmask),
326
                           "dev", master_netdev, "label",
327
                           "%s:0" % master_netdev])
323
                           "%s/%s" % (master_params.ip, master_params.netmask),
324
                           "dev", master_params.netdev, "label",
325
                           "%s:0" % master_params.netdev])
328 326
    if result.failed:
329 327
      err_msg = "Can't activate master IP: %s" % result.output
330 328
      logging.error(err_msg)
......
332 330
    else:
333 331
      # we ignore the exit code of the following cmds
334 332
      if ipcls == netutils.IP4Address:
335
        utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev, "-s",
336
                      master_ip, master_ip])
333
        utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_params.netdev,
334
                      "-s", master_params.ip, master_params.ip])
337 335
      elif ipcls == netutils.IP6Address:
338 336
        try:
339
          utils.RunCmd(["ndisc6", "-q", "-r 3", master_ip, master_netdev])
337
          utils.RunCmd(["ndisc6", "-q", "-r 3", master_params.ip,
338
                        master_params.netdev])
340 339
        except errors.OpExecError:
341 340
          # TODO: Better error reporting
342 341
          logging.warning("Can't execute ndisc6, please install if missing")
......
375 374

  
376 375
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNDOWN, "master-ip-turndown",
377 376
               _BuildMasterIpEnv)
378
def DeactivateMasterIp(master_ip, master_netmask, master_netdev, family):
377
def DeactivateMasterIp(master_params):
379 378
  """Deactivate the master IP on this node.
380 379

  
381
  @param master_ip: the master IP
382
  @param master_netmask: the master IP netmask
383
  @param master_netdev: the master network device
384
  @param family: the IP family
380
  @type master_params: L{objects.MasterNetworkParameters}
381
  @param master_params: network parameters of the master
385 382

  
386 383
  """
387
  # pylint: disable=W0613
388 384
  # TODO: log and report back to the caller the error failures; we
389 385
  # need to decide in which case we fail the RPC for this
390 386

  
391 387
  result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "del",
392
                         "%s/%s" % (master_ip, master_netmask),
393
                         "dev", master_netdev])
388
                         "%s/%s" % (master_params.ip, master_params.netmask),
389
                         "dev", master_params.netdev])
394 390
  if result.failed:
395 391
    logging.error("Can't remove the master IP, error: %s", result.output)
396 392
    # but otherwise ignore the failure

Also available in: Unified diff