@staticmethod
  def _CheckMods(kind, mods, key_types, item_fn):
    # Create a key_types copy with the 'uuid' as a valid key type.
    key_types_attach = key_types.copy()
    key_types_attach['uuid'] = 'string'

    for (op, _, params) in mods:
      assert ht.TDict(params)

      # If 'key_types' is an empty dict, we assume we have an
      # 'ext' template and thus do not ForceDictType
      if key_types:
        utils.ForceDictType(params, (key_types if op != constants.DDM_ATTACH
                                     else key_types_attach))

      if op in (constants.DDM_REMOVE, constants.DDM_DETACH):
        if params:
          raise errors.OpPrereqError("No settings should be passed when"
                                     " removing or detaching a %s" % kind,
                                     errors.ECODE_INVAL)
      elif op in (constants.DDM_ADD, constants.DDM_ATTACH,
                  constants.DDM_MODIFY):
        item_fn(op, params)
      else:
        raise errors.ProgrammerError("Unhandled operation '%s'" % op)
Ensures requested disk/NIC modifications are valid.
dataset/ETHPy150Open ganeti/ganeti/lib/cmdlib/instance_set_params.py/LUInstanceSetParams._CheckMods