Revision d8e0caa6 lib/backend.py

b/lib/backend.py
225 225
  for consumption here or from the node daemon.
226 226

  
227 227
  @rtype: tuple
228
  @return: master_netdev, master_ip, master_name
228
  @return: master_netdev, master_ip, master_name, primary_ip_family
229 229
  @raise RPCFail: in case of errors
230 230

  
231 231
  """
......
234 234
    master_netdev = cfg.GetMasterNetdev()
235 235
    master_ip = cfg.GetMasterIP()
236 236
    master_node = cfg.GetMasterNode()
237
    primary_ip_family = cfg.GetPrimaryIPFamily()
237 238
  except errors.ConfigurationError, err:
238 239
    _Fail("Cluster configuration incomplete: %s", err, exc=True)
239
  return (master_netdev, master_ip, master_node)
240
  return (master_netdev, master_ip, master_node, primary_ip_family)
240 241

  
241 242

  
242 243
def StartMaster(start_daemons, no_voting):
......
257 258

  
258 259
  """
259 260
  # GetMasterInfo will raise an exception if not able to return data
260
  master_netdev, master_ip, _ = GetMasterInfo()
261
  master_netdev, master_ip, _, family = GetMasterInfo()
261 262

  
262 263
  err_msgs = []
263 264
  # either start the master and rapi daemons
......
287 288
        logging.error(msg)
288 289
        err_msgs.append(msg)
289 290
    else:
290
      netmask = 32
291
      if netutils.IP6Address.IsValid(master_ip):
292
        netmask = 128
291
      ipcls = netutils.IP4Address
292
      if family == netutils.IP6Address.family:
293
        ipcls = netutils.IP6Address
293 294

  
294 295
      result = utils.RunCmd(["ip", "address", "add",
295
                             "%s/%d" % (master_ip, netmask),
296
                             "%s/%d" % (master_ip, ipcls.iplen),
296 297
                             "dev", master_netdev, "label",
297 298
                             "%s:0" % master_netdev])
298 299
      if result.failed:
......
301 302
        err_msgs.append(msg)
302 303

  
303 304
      # we ignore the exit code of the following cmds
304
      if netutils.IP4Address.IsValid(master_ip):
305
      if ipcls == netutils.IP4Address:
305 306
        utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev, "-s",
306 307
                      master_ip, master_ip])
307
      elif netutils.IP6Address.IsValid(master_ip):
308
      elif ipcls == netutils.IP6Address:
308 309
        utils.RunCmd(["ndisc6", "-q", "-r 3", master_ip, master_netdev])
309 310

  
310 311
  if err_msgs:
......
328 329
  # need to decide in which case we fail the RPC for this
329 330

  
330 331
  # GetMasterInfo will raise an exception if not able to return data
331
  master_netdev, master_ip, _ = GetMasterInfo()
332
  master_netdev, master_ip, _, family = GetMasterInfo()
332 333

  
333
  netmask = 32
334
  if netutils.IP6Address.IsValid(master_ip):
335
    netmask = 128
334
  ipcls = netutils.IP4Address
335
  if family == netutils.IP6Address.family:
336
    ipcls = netutils.IP6Address
336 337

  
337 338
  result = utils.RunCmd(["ip", "address", "del",
338
                         "%s/%d" % (master_ip, netmask),
339
                         "%s/%d" % (master_ip, ipcls.iplen),
339 340
                         "dev", master_netdev])
340 341
  if result.failed:
341 342
    logging.error("Can't remove the master IP, error: %s", result.output)

Also available in: Unified diff