Revision 73e0328b

b/lib/cmdlib.py
751 751

  
752 752
  """
753 753
  hooks_nics = []
754
  c_nicparams = lu.cfg.GetClusterInfo().nicparams[constants.PP_DEFAULT]
754
  cluster = lu.cfg.GetClusterInfo()
755 755
  for nic in nics:
756 756
    ip = nic.ip
757 757
    mac = nic.mac
758
    filled_params = objects.FillDict(c_nicparams, nic.nicparams)
758
    filled_params = cluster.SimpleFillNIC(nic.nicparams)
759 759
    mode = filled_params[constants.NIC_MODE]
760 760
    link = filled_params[constants.NIC_LINK]
761 761
    hooks_nics.append((ip, mac, mode, link))
......
827 827
  return mc_now < mc_should
828 828

  
829 829

  
830
def _CheckNicsBridgesExist(lu, target_nics, target_node,
831
                               profile=constants.PP_DEFAULT):
830
def _CheckNicsBridgesExist(lu, target_nics, target_node):
832 831
  """Check that the brigdes needed by a list of nics exist.
833 832

  
834 833
  """
835
  c_nicparams = lu.cfg.GetClusterInfo().nicparams[profile]
836
  paramslist = [objects.FillDict(c_nicparams, nic.nicparams)
837
                for nic in target_nics]
834
  cluster = lu.cfg.GetClusterInfo()
835
  paramslist = [cluster.SimpleFillNIC(nic.nicparams) for nic in target_nics]
838 836
  brlist = [params[constants.NIC_LINK] for params in paramslist
839 837
            if params[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED]
840 838
  if brlist:
......
2332 2330
    # validate params changes
2333 2331
    if self.op.beparams:
2334 2332
      utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
2335
      self.new_beparams = objects.FillDict(
2336
        cluster.beparams[constants.PP_DEFAULT], self.op.beparams)
2333
      self.new_beparams = cluster.SimpleFillBE(self.op.beparams)
2337 2334

  
2338 2335
    if self.op.nicparams:
2339 2336
      utils.ForceDictType(self.op.nicparams, constants.NICS_PARAMETER_TYPES)
2340
      self.new_nicparams = objects.FillDict(
2341
        cluster.nicparams[constants.PP_DEFAULT], self.op.nicparams)
2337
      self.new_nicparams = cluster.SimpleFillNIC(self.op.nicparams)
2342 2338
      objects.NIC.CheckParameterSyntax(self.new_nicparams)
2343 2339
      nic_errors = []
2344 2340

  
......
4816 4812
      iout = []
4817 4813
      i_hv = cluster.FillHV(instance, skip_globals=True)
4818 4814
      i_be = cluster.FillBE(instance)
4819
      i_nicp = [objects.FillDict(cluster.nicparams[constants.PP_DEFAULT],
4820
                                 nic.nicparams) for nic in instance.nics]
4815
      i_nicp = [cluster.SimpleFillNIC(nic.nicparams) for nic in instance.nics]
4821 4816
      for field in self.op.output_fields:
4822 4817
        st_match = self._FIELDS_STATIC.Matches(field)
4823 4818
        if field in self._SIMPLE_FIELDS:
......
6470 6465

  
6471 6466
    """
6472 6467
    # hvparams
6473
    hv_defs = cluster.GetHVDefaults(self.op.hypervisor, self.op.os_type)
6468
    hv_defs = cluster.SimpleFillHV(self.op.hypervisor, self.op.os_type, {})
6474 6469
    for name in self.op.hvparams.keys():
6475 6470
      if name in hv_defs and hv_defs[name] == self.op.hvparams[name]:
6476 6471
        del self.op.hvparams[name]
6477 6472
    # beparams
6478
    be_defs = cluster.beparams.get(constants.PP_DEFAULT, {})
6473
    be_defs = cluster.SimpleFillBE({})
6479 6474
    for name in self.op.beparams.keys():
6480 6475
      if name in be_defs and be_defs[name] == self.op.beparams[name]:
6481 6476
        del self.op.beparams[name]
6482 6477
    # nic params
6483
    nic_defs = cluster.nicparams.get(constants.PP_DEFAULT, {})
6478
    nic_defs = cluster.SimpleFillNIC({})
6484 6479
    for nic in self.op.nics:
6485 6480
      for name in constants.NICS_PARAMETERS:
6486 6481
        if name in nic and name in nic_defs and nic[name] == nic_defs[name]:
......
6514 6509

  
6515 6510
    # check hypervisor parameter syntax (locally)
6516 6511
    utils.ForceDictType(self.op.hvparams, constants.HVS_PARAMETER_TYPES)
6517
    filled_hvp = objects.FillDict(cluster.GetHVDefaults(self.op.hypervisor,
6518
                                                        self.op.os_type),
6519
                                  self.op.hvparams)
6512
    filled_hvp = cluster.SimpleFillHV(self.op.hypervisor, self.op.os_type,
6513
                                      self.op.hvparams)
6520 6514
    hv_type = hypervisor.GetHypervisor(self.op.hypervisor)
6521 6515
    hv_type.CheckParameterSyntax(filled_hvp)
6522 6516
    self.hv_full = filled_hvp
......
6525 6519

  
6526 6520
    # fill and remember the beparams dict
6527 6521
    utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
6528
    self.be_full = objects.FillDict(cluster.beparams[constants.PP_DEFAULT],
6529
                                    self.op.beparams)
6522
    self.be_full = cluster.SimpleFillBE(self.op.beparams)
6530 6523

  
6531 6524
    # now that hvp/bep are in final format, let's reset to defaults,
6532 6525
    # if told to do so
......
6599 6592
      if link:
6600 6593
        nicparams[constants.NIC_LINK] = link
6601 6594

  
6602
      check_params = objects.FillDict(cluster.nicparams[constants.PP_DEFAULT],
6603
                                      nicparams)
6595
      check_params = cluster.SimpleFillNIC(nicparams)
6604 6596
      objects.NIC.CheckParameterSyntax(check_params)
6605 6597
      self.nics.append(objects.NIC(mac=mac, ip=nic_ip, nicparams=nicparams))
6606 6598

  
......
8382 8374
    if self.op.nics:
8383 8375
      args['nics'] = []
8384 8376
      nic_override = dict(self.op.nics)
8385
      c_nicparams = self.cluster.nicparams[constants.PP_DEFAULT]
8386 8377
      for idx, nic in enumerate(self.instance.nics):
8387 8378
        if idx in nic_override:
8388 8379
          this_nic_override = nic_override[idx]
......
8399 8390
        if idx in self.nic_pnew:
8400 8391
          nicparams = self.nic_pnew[idx]
8401 8392
        else:
8402
          nicparams = objects.FillDict(c_nicparams, nic.nicparams)
8393
          nicparams = self.cluster.SimpleFillNIC(nic.nicparams)
8403 8394
        mode = nicparams[constants.NIC_MODE]
8404 8395
        link = nicparams[constants.NIC_LINK]
8405 8396
        args['nics'].append((ip, mac, mode, link))
......
9699 9690
    for iinfo, beinfo in i_list:
9700 9691
      nic_data = []
9701 9692
      for nic in iinfo.nics:
9702
        filled_params = objects.FillDict(
9703
            cluster_info.nicparams[constants.PP_DEFAULT],
9704
            nic.nicparams)
9693
        filled_params = cluster_info.SimpleFillNIC(nic.nicparams)
9705 9694
        nic_dict = {"mac": nic.mac,
9706 9695
                    "ip": nic.ip,
9707 9696
                    "mode": filled_params[constants.NIC_MODE],
b/lib/objects.py
961 961

  
962 962
    return ret_dict
963 963

  
964
  def SimpleFillHV(self, hv_name, os_name, hvparams, skip_globals=False):
965
    """Fill a given hvparams dict with cluster defaults.
966

  
967
    @type hv_name: string
968
    @param hv_name: the hypervisor to use
969
    @type os_name: string
970
    @param os_name: the OS to use for overriding the hypervisor defaults
971
    @type skip_globals: boolean
972
    @param skip_globals: if True, the global hypervisor parameters will
973
        not be filled
974
    @rtype: dict
975
    @return: a copy of the given hvparams with missing keys filled from
976
        the cluster defaults
977

  
978
    """
979
    if skip_globals:
980
      skip_keys = constants.HVC_GLOBALS
981
    else:
982
      skip_keys = []
983

  
984
    def_dict = self.GetHVDefaults(hv_name, os_name, skip_keys=skip_keys)
985
    return FillDict(def_dict, hvparams, skip_keys=skip_keys)
964 986

  
965 987
  def FillHV(self, instance, skip_globals=False):
966
    """Fill an instance's hvparams dict.
988
    """Fill an instance's hvparams dict with cluster defaults.
967 989

  
968 990
    @type instance: L{objects.Instance}
969 991
    @param instance: the instance parameter to fill
......
975 997
        the cluster defaults
976 998

  
977 999
    """
978
    if skip_globals:
979
      skip_keys = constants.HVC_GLOBALS
980
    else:
981
      skip_keys = []
1000
    return self.SimpleFillHV(instance.hypervisor, instance.os,
1001
                             instance.hvparams, skip_globals)
982 1002

  
983
    def_dict = self.GetHVDefaults(instance.hypervisor, instance.os,
984
                                  skip_keys=skip_keys)
985
    return FillDict(def_dict, instance.hvparams, skip_keys=skip_keys)
1003
  def SimpleFillBE(self, beparams):
1004
    """Fill a given beparams dict with cluster defaults.
1005

  
1006
    @type beparam: dict
1007
    @param beparam: the dict to fill
1008
    @rtype: dict
1009
    @return: a copy of the passed in beparams with missing keys filled
1010
        from the cluster defaults
1011

  
1012
    """
1013
    return FillDict(self.beparams.get(constants.PP_DEFAULT, {}), beparams)
986 1014

  
987 1015
  def FillBE(self, instance):
988
    """Fill an instance's beparams dict.
1016
    """Fill an instance's beparams dict with cluster defaults.
989 1017

  
990 1018
    @type instance: L{objects.Instance}
991 1019
    @param instance: the instance parameter to fill
......
994 1022
        the cluster defaults
995 1023

  
996 1024
    """
997
    return FillDict(self.beparams.get(constants.PP_DEFAULT, {}),
998
                    instance.beparams)
1025
    return self.SimpleFillBE(instance.beparams)
1026

  
1027
  def SimpleFillNIC(self, nicparams):
1028
    """Fill a given nicparams dict with cluster defaults.
1029

  
1030
    @type nicparam: dict
1031
    @param nicparam: the dict to fill
1032
    @rtype: dict
1033
    @return: a copy of the passed in nicparams with missing keys filled
1034
        from the cluster defaults
1035

  
1036
    """
1037
    return FillDict(self.nicparams.get(constants.PP_DEFAULT, {}), nicparams)
999 1038

  
1000 1039

  
1001 1040
class BlockDevStatus(ConfigObject):

Also available in: Unified diff