Revision abe609b2

b/lib/cmdlib.py
1489 1489
    # validate beparams changes
1490 1490
    if self.op.beparams:
1491 1491
      utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
1492
      self.new_beparams = cluster.FillDict(
1492
      self.new_beparams = objects.FillDict(
1493 1493
        cluster.beparams[constants.BEGR_DEFAULT], self.op.beparams)
1494 1494

  
1495 1495
    # hypervisor list/parameters
1496
    self.new_hvparams = cluster.FillDict(cluster.hvparams, {})
1496
    self.new_hvparams = objects.FillDict(cluster.hvparams, {})
1497 1497
    if self.op.hvparams:
1498 1498
      if not isinstance(self.op.hvparams, dict):
1499 1499
        raise errors.OpPrereqError("Invalid 'hvparams' parameter on input")
......
2848 2848
      # check hypervisor parameter syntax (locally)
2849 2849
      cluster = self.cfg.GetClusterInfo()
2850 2850
      utils.ForceDictType(self.hvparams, constants.HVS_PARAMETER_TYPES)
2851
      filled_hvp = cluster.FillDict(cluster.hvparams[instance.hypervisor],
2851
      filled_hvp = objects.FillDict(cluster.hvparams[instance.hypervisor],
2852 2852
                                    instance.hvparams)
2853 2853
      filled_hvp.update(self.hvparams)
2854 2854
      hv_type = hypervisor.GetHypervisor(instance.hypervisor)
......
4404 4404

  
4405 4405
    # check hypervisor parameter syntax (locally)
4406 4406
    utils.ForceDictType(self.op.hvparams, constants.HVS_PARAMETER_TYPES)
4407
    filled_hvp = cluster.FillDict(cluster.hvparams[self.op.hypervisor],
4407
    filled_hvp = objects.FillDict(cluster.hvparams[self.op.hypervisor],
4408 4408
                                  self.op.hvparams)
4409 4409
    hv_type = hypervisor.GetHypervisor(self.op.hypervisor)
4410 4410
    hv_type.CheckParameterSyntax(filled_hvp)
4411 4411

  
4412 4412
    # fill and remember the beparams dict
4413 4413
    utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
4414
    self.be_full = cluster.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
4414
    self.be_full = objects.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
4415 4415
                                    self.op.beparams)
4416 4416

  
4417 4417
    #### instance parameters check
......
5963 5963
          i_hvdict[key] = val
5964 5964
      cluster = self.cfg.GetClusterInfo()
5965 5965
      utils.ForceDictType(i_hvdict, constants.HVS_PARAMETER_TYPES)
5966
      hv_new = cluster.FillDict(cluster.hvparams[instance.hypervisor],
5966
      hv_new = objects.FillDict(cluster.hvparams[instance.hypervisor],
5967 5967
                                i_hvdict)
5968 5968
      # local check
5969 5969
      hypervisor.GetHypervisor(
......
5987 5987
          i_bedict[key] = val
5988 5988
      cluster = self.cfg.GetClusterInfo()
5989 5989
      utils.ForceDictType(i_bedict, constants.BES_PARAMETER_TYPES)
5990
      be_new = cluster.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
5990
      be_new = objects.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
5991 5991
                                i_bedict)
5992 5992
      self.be_new = be_new # the new actual values
5993 5993
      self.be_inst = i_bedict # the new dict (without defaults)
b/lib/objects.py
37 37

  
38 38

  
39 39
__all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
40
           "OS", "Node", "Cluster"]
40
           "OS", "Node", "Cluster", "FillDict"]
41 41

  
42
def FillDict(defaults_dict, custom_dict):
43
    """Basic function to apply settings on top a default dict.
44

  
45
    @type defaults_dict: dict
46
    @param defaults_dict: dictionary holding the default values
47
    @type custom_dict: dict
48
    @param custom_dict: dictionary holding customized value
49
    @rtype: dict
50
    @return: dict with the 'full' values
51

  
52
    """
53
    ret_dict = copy.deepcopy(defaults_dict)
54
    ret_dict.update(custom_dict)
55
    return ret_dict
42 56

  
43 57
class ConfigObject(object):
44 58
  """A generic config object.
......
746 760
      self.hvparams = constants.HVC_DEFAULTS
747 761
    else:
748 762
      for hypervisor in self.hvparams:
749
        self.hvparams[hypervisor] = self.FillDict(
763
        self.hvparams[hypervisor] = FillDict(
750 764
            constants.HVC_DEFAULTS[hypervisor], self.hvparams[hypervisor])
751 765

  
752 766
    if self.beparams is None:
753 767
      self.beparams = {constants.BEGR_DEFAULT: constants.BEC_DEFAULTS}
754 768
    else:
755 769
      for begroup in self.beparams:
756
        self.beparams[begroup] = self.FillDict(constants.BEC_DEFAULTS,
770
        self.beparams[begroup] = FillDict(constants.BEC_DEFAULTS,
757 771
                                               self.beparams[begroup])
758 772

  
759 773
    if self.modify_etc_hosts is None:
......
777 791
      obj.tcpudp_port_pool = set(obj.tcpudp_port_pool)
778 792
    return obj
779 793

  
780
  @staticmethod
781
  def FillDict(defaults_dict, custom_dict):
782
    """Basic function to apply settings on top a default dict.
783

  
784
    @type defaults_dict: dict
785
    @param defaults_dict: dictionary holding the default values
786
    @type custom_dict: dict
787
    @param custom_dict: dictionary holding customized value
788
    @rtype: dict
789
    @return: dict with the 'full' values
790

  
791
    """
792
    ret_dict = copy.deepcopy(defaults_dict)
793
    ret_dict.update(custom_dict)
794
    return ret_dict
795

  
796 794
  def FillHV(self, instance):
797 795
    """Fill an instance's hvparams dict.
798 796

  
......
803 801
        the cluster defaults
804 802

  
805 803
    """
806
    return self.FillDict(self.hvparams.get(instance.hypervisor, {}),
804
    return FillDict(self.hvparams.get(instance.hypervisor, {}),
807 805
                         instance.hvparams)
808 806

  
809 807
  def FillBE(self, instance):
......
816 814
        the cluster defaults
817 815

  
818 816
    """
819
    return self.FillDict(self.beparams.get(constants.BEGR_DEFAULT, {}),
817
    return FillDict(self.beparams.get(constants.BEGR_DEFAULT, {}),
820 818
                         instance.beparams)
821 819

  
822 820

  
b/lib/rpc.py
1135 1135

  
1136 1136
    """
1137 1137
    cluster = self._cfg.GetClusterInfo()
1138
    hv_full = cluster.FillDict(cluster.hvparams.get(hvname, {}), hvparams)
1138
    hv_full = objects.FillDict(cluster.hvparams.get(hvname, {}), hvparams)
1139 1139
    return self._MultiNodeCall(node_list, "hypervisor_validate_params",
1140 1140
                               [hvname, hv_full])

Also available in: Unified diff