Revision abe609b2 lib/objects.py
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 |
|
Also available in: Unified diff