Revision 250a9404 lib/cmdlib.py

b/lib/cmdlib.py
1020 1020
                               % ",".join(delta), errors.ECODE_INVAL)
1021 1021

  
1022 1022

  
1023
def _CheckGlobalHvParams(params):
1024
  """Validates that given hypervisor params are not global ones.
1023
def _CheckParamsNotGlobal(params, glob_pars, kind, bad_levels, good_levels):
1024
  """Make sure that none of the given paramters is global.
1025 1025

  
1026
  This will ensure that instances don't get customised versions of
1027
  global params.
1026
  If a global parameter is found, an L{errors.OpPrereqError} exception is
1027
  raised. This is used to avoid setting global parameters for individual nodes.
1028

  
1029
  @type params: dictionary
1030
  @param params: Parameters to check
1031
  @type glob_pars: dictionary
1032
  @param glob_pars: Forbidden parameters
1033
  @type kind: string
1034
  @param kind: Kind of parameters (e.g. "node")
1035
  @type bad_levels: string
1036
  @param bad_levels: Level(s) at which the parameters are forbidden (e.g.
1037
      "instance")
1038
  @type good_levels: strings
1039
  @param good_levels: Level(s) at which the parameters are allowed (e.g.
1040
      "cluster or group")
1028 1041

  
1029 1042
  """
1030
  used_globals = constants.HVC_GLOBALS.intersection(params)
1043
  used_globals = glob_pars.intersection(params)
1031 1044
  if used_globals:
1032
    msg = ("The following hypervisor parameters are global and cannot"
1033
           " be customized at instance level, please modify them at"
1034
           " cluster level: %s" % utils.CommaJoin(used_globals))
1045
    msg = ("The following %s parameters are global and cannot"
1046
           " be customized at %s level, please modify them at"
1047
           " %s level: %s" %
1048
           (kind, bad_levels, good_levels, utils.CommaJoin(used_globals)))
1035 1049
    raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
1036 1050

  
1037 1051

  
......
6129 6143

  
6130 6144
    if self.op.ndparams:
6131 6145
      utils.ForceDictType(self.op.ndparams, constants.NDS_PARAMETER_TYPES)
6146
      _CheckParamsNotGlobal(self.op.ndparams, constants.NDC_GLOBALS, "node",
6147
                            "node", "cluster or group")
6132 6148

  
6133 6149
    if self.op.hv_state:
6134 6150
      self.new_hv_state = _MergeAndVerifyHvState(self.op.hv_state, None)
......
6154 6170
    if vg_name is not None:
6155 6171
      vparams = {constants.NV_PVLIST: [vg_name]}
6156 6172
      excl_stor = _IsExclusiveStorageEnabledNode(cfg, self.new_node)
6157
      if self.op.ndparams:
6158
        excl_stor = self.op.ndparams.get(constants.ND_EXCLUSIVE_STORAGE,
6159
                                         excl_stor)
6160 6173
      cname = self.cfg.GetClusterName()
6161 6174
      result = rpcrunner.call_node_verify_light([node], vparams, cname)[node]
6162 6175
      (errmsgs, _) = _CheckNodePVs(result.payload, excl_stor)
......
6554 6567
    if self.op.ndparams:
6555 6568
      new_ndparams = _GetUpdatedParams(self.node.ndparams, self.op.ndparams)
6556 6569
      utils.ForceDictType(new_ndparams, constants.NDS_PARAMETER_TYPES)
6570
      _CheckParamsNotGlobal(self.op.ndparams, constants.NDC_GLOBALS, "node",
6571
                            "node", "cluster or group")
6557 6572
      self.new_ndparams = new_ndparams
6558 6573

  
6559 6574
    if self.op.hv_state:
......
10592 10607
    hv_type.CheckParameterSyntax(filled_hvp)
10593 10608
    self.hv_full = filled_hvp
10594 10609
    # check that we don't specify global parameters on an instance
10595
    _CheckGlobalHvParams(self.op.hvparams)
10610
    _CheckParamsNotGlobal(self.op.hvparams, constants.HVC_GLOBALS, "hypervisor",
10611
                          "instance", "cluster")
10596 10612

  
10597 10613
    # fill and remember the beparams dict
10598 10614
    self.be_full = _ComputeFullBeParams(self.op, cluster)
......
13290 13306
      raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL)
13291 13307

  
13292 13308
    if self.op.hvparams:
13293
      _CheckGlobalHvParams(self.op.hvparams)
13309
      _CheckParamsNotGlobal(self.op.hvparams, constants.HVC_GLOBALS,
13310
                            "hypervisor", "instance", "cluster")
13294 13311

  
13295 13312
    self.op.disks = self._UpgradeDiskNicMods(
13296 13313
      "disk", self.op.disks, opcodes.OpInstanceSetParams.TestDiskModifications)

Also available in: Unified diff