Revision 5c44da6a

b/lib/cmdlib.py
5675 5675
      # nic_dict should be a dict
5676 5676
      nic_ip = nic_dict.get('ip', None)
5677 5677
      if nic_ip is not None:
5678
        if nic_ip.lower() == "none":
5678
        if nic_ip.lower() == constants.VALUE_NONE:
5679 5679
          nic_dict['ip'] = None
5680 5680
        else:
5681 5681
          if not utils.IsValidIP(nic_ip):
5682 5682
            raise errors.OpPrereqError("Invalid IP address '%s'" % nic_ip)
5683
      # we can only check None bridges and assign the default one
5684
      nic_bridge = nic_dict.get('bridge', None)
5685
      if nic_bridge is None:
5686
        nic_dict['bridge'] = self.cfg.GetDefBridge()
5687
      # but we can validate MACs
5688
      nic_mac = nic_dict.get('mac', None)
5689
      if nic_mac is not None:
5690
        if self.cfg.IsMacInUse(nic_mac):
5691
          raise errors.OpPrereqError("MAC address %s already in use"
5692
                                     " in cluster" % nic_mac)
5683

  
5684
      if nic_op == constants.DDM_ADD:
5685
        nic_bridge = nic_dict.get('bridge', None)
5686
        if nic_bridge is None:
5687
          nic_dict['bridge'] = self.cfg.GetDefBridge()
5688
        nic_mac = nic_dict.get('mac', None)
5689
        if nic_mac is None:
5690
          nic_dict['mac'] = constants.VALUE_AUTO
5691

  
5692
      if 'mac' in nic_dict:
5693
        nic_mac = nic_dict['mac']
5693 5694
        if nic_mac not in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
5694 5695
          if not utils.IsValidMac(nic_mac):
5695 5696
            raise errors.OpPrereqError("Invalid MAC address %s" % nic_mac)
5697
        if nic_op != constants.DDM_ADD and nic_mac == constants.VALUE_AUTO:
5698
          raise errors.OpPrereqError("'auto' is not a valid MAC address when"
5699
                                     " modifying an existing nic")
5700

  
5696 5701
    if nic_addremove > 1:
5697 5702
      raise errors.OpPrereqError("Only one NIC add or remove operation"
5698 5703
                                 " supported at a time")
......
5833 5838
          raise errors.OpPrereqError("Invalid NIC index %s, valid values"
5834 5839
                                     " are 0 to %d" %
5835 5840
                                     (nic_op, len(instance.nics)))
5836
      nic_bridge = nic_dict.get('bridge', None)
5837
      if nic_bridge is not None:
5841
      if 'bridge' in nic_dict:
5842
        nic_bridge = nic_dict['bridge']
5843
        if nic_bridge is None:
5844
          raise errors.OpPrereqError('Cannot set the nic bridge to None')
5838 5845
        if not self.rpc.call_bridges_exist(pnode, [nic_bridge]):
5839 5846
          msg = ("Bridge '%s' doesn't exist on one of"
5840 5847
                 " the instance nodes" % nic_bridge)
......
5842 5849
            self.warn.append(msg)
5843 5850
          else:
5844 5851
            raise errors.OpPrereqError(msg)
5852
      if 'mac' in nic_dict:
5853
        nic_mac = nic_dict['mac']
5854
        if nic_mac is None:
5855
          raise errors.OpPrereqError('Cannot set the nic mac to None')
5856
        elif nic_mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
5857
          # otherwise generate the mac
5858
          nic_dict['mac'] = self.cfg.GenerateMAC()
5859
        else:
5860
          # or validate/reserve the current one
5861
          if self.cfg.IsMacInUse(nic_mac):
5862
            raise errors.OpPrereqError("MAC address %s already in use"
5863
                                       " in cluster" % nic_mac)
5845 5864

  
5846 5865
    # DISK processing
5847 5866
    if self.op.disks and instance.disk_template == constants.DT_DISKLESS:
......
5944 5963
        del instance.nics[-1]
5945 5964
        result.append(("nic.%d" % len(instance.nics), "remove"))
5946 5965
      elif nic_op == constants.DDM_ADD:
5947
        # add a new nic
5948
        if 'mac' not in nic_dict:
5949
          mac = constants.VALUE_GENERATE
5950
        else:
5951
          mac = nic_dict['mac']
5952
        if mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
5953
          mac = self.cfg.GenerateMAC()
5966
        # mac and bridge should be set, by now
5967
        mac = nic_dict['mac']
5968
        bridge = nic_dict['bridge']
5954 5969
        new_nic = objects.NIC(mac=mac, ip=nic_dict.get('ip', None),
5955
                              bridge=nic_dict.get('bridge', None))
5970
                              bridge=bridge)
5956 5971
        instance.nics.append(new_nic)
5957 5972
        result.append(("nic.%d" % (len(instance.nics) - 1),
5958 5973
                       "add:mac=%s,ip=%s,bridge=%s" %

Also available in: Unified diff