Revision aa6c1bb1

b/lib/cmdlib.py
12865 12865
    for (op, _, params) in mods:
12866 12866
      assert ht.TDict(params)
12867 12867

  
12868
      utils.ForceDictType(params, key_types)
12868
      # If 'key_types' is an empty dict, we assume we have an
12869
      # 'ext' template and thus do not ForceDictType
12870
      if key_types:
12871
        utils.ForceDictType(params, key_types)
12869 12872

  
12870 12873
      if op == constants.DDM_REMOVE:
12871 12874
        if params:
......
12901 12904

  
12902 12905
      params[constants.IDISK_SIZE] = size
12903 12906

  
12904
    elif op == constants.DDM_MODIFY and constants.IDISK_SIZE in params:
12905
      raise errors.OpPrereqError("Disk size change not possible, use"
12906
                                 " grow-disk", errors.ECODE_INVAL)
12907
    elif op == constants.DDM_MODIFY:
12908
      if constants.IDISK_SIZE in params:
12909
        raise errors.OpPrereqError("Disk size change not possible, use"
12910
                                   " grow-disk", errors.ECODE_INVAL)
12911
      if constants.IDISK_MODE not in params:
12912
        raise errors.OpPrereqError("Disk 'mode' is the only kind of"
12913
                                   " modification supported, but missing",
12914
                                   errors.ECODE_NOENT)
12915
      if len(params) > 1:
12916
        raise errors.OpPrereqError("Disk modification doesn't support"
12917
                                   " additional arbitrary parameters",
12918
                                   errors.ECODE_INVAL)
12907 12919

  
12908 12920
  @staticmethod
12909 12921
  def _VerifyNicModification(op, params):
......
12967 12979
    self.op.nics = self._UpgradeDiskNicMods(
12968 12980
      "NIC", self.op.nics, opcodes.OpInstanceSetParams.TestNicModifications)
12969 12981

  
12970
    # Check disk modifications
12971
    self._CheckMods("disk", self.op.disks, constants.IDISK_PARAMS_TYPES,
12972
                    self._VerifyDiskModification)
12973

  
12974 12982
    if self.op.disks and self.op.disk_template is not None:
12975 12983
      raise errors.OpPrereqError("Disk template conversion and other disk"
12976 12984
                                 " changes not supported at the same time",
......
13185 13193
    private.params = new_params
13186 13194
    private.filled = new_filled_params
13187 13195

  
13188
  def CheckPrereq(self):
13196
  def CheckPrereq(self): # pylint: disable=R0914
13189 13197
    """Check prerequisites.
13190 13198

  
13191 13199
    This only checks the instance list against the existing names.
......
13211 13219
    # dictionary with instance information after the modification
13212 13220
    ispec = {}
13213 13221

  
13222
    # Check disk modifications. This is done here and not in CheckArguments
13223
    # (as with NICs), because we need to know the instance's disk template
13224
    if instance.disk_template == constants.DT_EXT:
13225
      self._CheckMods("disk", self.op.disks, {},
13226
                      self._VerifyDiskModification)
13227
    else:
13228
      self._CheckMods("disk", self.op.disks, constants.IDISK_PARAMS_TYPES,
13229
                      self._VerifyDiskModification)
13230

  
13214 13231
    # Prepare disk/NIC modifications
13215 13232
    self.diskmod = PrepareContainerMods(self.op.disks, None)
13216 13233
    self.nicmod = PrepareContainerMods(self.op.nics, _InstNicModPrivate)
13217 13234

  
13235
    # Check the validity of the `provider' parameter
13236
    if instance.disk_template in constants.DT_EXT:
13237
      for mod in self.diskmod:
13238
        ext_provider = mod[2].get(constants.IDISK_PROVIDER, None)
13239
        if mod[0] == constants.DDM_ADD:
13240
          if ext_provider is None:
13241
            raise errors.OpPrereqError("Instance template is '%s' and parameter"
13242
                                       " '%s' missing, during disk add" %
13243
                                       (constants.DT_EXT,
13244
                                        constants.IDISK_PROVIDER),
13245
                                       errors.ECODE_NOENT)
13246
        elif mod[0] == constants.DDM_MODIFY:
13247
          if ext_provider:
13248
            raise errors.OpPrereqError("Parameter '%s' is invalid during disk"
13249
                                       " modification" %
13250
                                       constants.IDISK_PROVIDER,
13251
                                       errors.ECODE_INVAL)
13252
    else:
13253
      for mod in self.diskmod:
13254
        ext_provider = mod[2].get(constants.IDISK_PROVIDER, None)
13255
        if ext_provider is not None:
13256
          raise errors.OpPrereqError("Parameter '%s' is only valid for"
13257
                                     " instances of type '%s'" %
13258
                                     (constants.IDISK_PROVIDER,
13259
                                      constants.DT_EXT),
13260
                                     errors.ECODE_INVAL)
13261

  
13218 13262
    # OS change
13219 13263
    if self.op.os_name and not self.op.force:
13220 13264
      _CheckNodeHasOS(self, instance.primary_node, self.op.os_name,

Also available in: Unified diff