Revision 9dce4771 lib/cmdlib.py

b/lib/cmdlib.py
4440 4440

  
4441 4441
    # NIC buildup
4442 4442
    self.nics = []
4443
    for nic in self.op.nics:
4443
    for idx, nic in enumerate(self.op.nics):
4444
      nic_mode_req = nic.get("mode", None)
4445
      nic_mode = nic_mode_req
4446
      if nic_mode is None:
4447
        nic_mode = cluster.nicparams[constants.PP_DEFAULT][constants.NIC_MODE]
4448

  
4449
      # in routed mode, for the first nic, the default ip is 'auto'
4450
      if nic_mode == constants.NIC_MODE_ROUTED and idx == 0:
4451
        default_ip_mode = constants.VALUE_AUTO
4452
      else:
4453
        default_ip_mode = constants.VALUE_NONE
4454

  
4444 4455
      # ip validity checks
4445
      ip = nic.get("ip", None)
4446
      if ip is None or ip.lower() == "none":
4456
      ip = nic.get("ip", default_ip_mode)
4457
      if ip is None or ip.lower() == constants.VALUE_NONE:
4447 4458
        nic_ip = None
4448 4459
      elif ip.lower() == constants.VALUE_AUTO:
4449 4460
        nic_ip = hostname1.ip
......
4453 4464
                                     " like a valid IP" % ip)
4454 4465
        nic_ip = ip
4455 4466

  
4467
      # TODO: check the ip for uniqueness !!
4468
      if nic_mode == constants.NIC_MODE_ROUTED and not nic_ip:
4469
        raise errors.OpPrereqError("Routed nic mode requires an ip address")
4470

  
4456 4471
      # MAC address verification
4457 4472
      mac = nic.get("mac", constants.VALUE_AUTO)
4458 4473
      if mac not in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
......
4461 4476
                                     mac)
4462 4477
      # bridge verification
4463 4478
      bridge = nic.get("bridge", None)
4464
      if bridge is None:
4465
        bridge = self.cfg.GetDefBridge()
4466
      self.nics.append(objects.NIC(mac=mac, ip=nic_ip, bridge=bridge))
4479
      link = nic.get("link", None)
4480
      if bridge and link:
4481
        raise errors.OpPrereqError("Cannot pass 'bridge' and 'link' at the same time")
4482
      elif bridge and nic_mode == constants.NIC_MODE_ROUTED:
4483
        raise errors.OpPrereqError("Cannot pass 'bridge' on a routed nic")
4484
      elif bridge:
4485
        link = bridge
4486

  
4487
      nicparams = {}
4488
      if nic_mode_req:
4489
        nicparams[constants.NIC_MODE] = nic_mode_req
4490
      if link:
4491
        nicparams[constants.NIC_LINK] = link
4492

  
4493
      check_params = objects.FillDict(cluster.nicparams[constants.PP_DEFAULT],
4494
                                      nicparams)
4495
      objects.NIC.CheckParameterSyntax(check_params)
4496
      self.nics.append(objects.NIC(mac=mac, ip=nic_ip, nicparams=nicparams))
4467 4497

  
4468 4498
    # disk checks/pre-build
4469 4499
    self.disks = []

Also available in: Unified diff