Revision 7736a5f2 lib/objects.py
b/lib/objects.py | ||
---|---|---|
42 | 42 |
_TIMESTAMPS = ["ctime", "mtime"] |
43 | 43 |
_UUID = ["uuid"] |
44 | 44 |
|
45 |
def FillDict(defaults_dict, custom_dict): |
|
45 |
def FillDict(defaults_dict, custom_dict, skip_keys=[]):
|
|
46 | 46 |
"""Basic function to apply settings on top a default dict. |
47 | 47 |
|
48 | 48 |
@type defaults_dict: dict |
49 | 49 |
@param defaults_dict: dictionary holding the default values |
50 | 50 |
@type custom_dict: dict |
51 | 51 |
@param custom_dict: dictionary holding customized value |
52 |
@type skip_keys: list |
|
53 |
@param skip_keys: which keys not to fill |
|
52 | 54 |
@rtype: dict |
53 | 55 |
@return: dict with the 'full' values |
54 | 56 |
|
55 | 57 |
""" |
56 | 58 |
ret_dict = copy.deepcopy(defaults_dict) |
57 | 59 |
ret_dict.update(custom_dict) |
60 |
for k in skip_keys: |
|
61 |
try: |
|
62 |
del ret_dict[k] |
|
63 |
except KeyError: |
|
64 |
pass |
|
58 | 65 |
return ret_dict |
59 | 66 |
|
60 | 67 |
|
... | ... | |
777 | 784 |
nic.UpgradeConfig() |
778 | 785 |
for disk in self.disks: |
779 | 786 |
disk.UpgradeConfig() |
787 |
if self.hvparams: |
|
788 |
for key in constants.HVC_GLOBALS: |
|
789 |
try: |
|
790 |
del self.hvparams[key] |
|
791 |
except KeyError: |
|
792 |
pass |
|
780 | 793 |
|
781 | 794 |
|
782 | 795 |
class OS(ConfigObject): |
... | ... | |
887 | 900 |
obj.tcpudp_port_pool = set(obj.tcpudp_port_pool) |
888 | 901 |
return obj |
889 | 902 |
|
890 |
def FillHV(self, instance): |
|
903 |
def FillHV(self, instance, skip_globals=False):
|
|
891 | 904 |
"""Fill an instance's hvparams dict. |
892 | 905 |
|
893 | 906 |
@type instance: L{objects.Instance} |
894 | 907 |
@param instance: the instance parameter to fill |
908 |
@type skip_globals: boolean |
|
909 |
@param skip_globals: if True, the global hypervisor parameters will |
|
910 |
not be filled |
|
895 | 911 |
@rtype: dict |
896 | 912 |
@return: a copy of the instance's hvparams with missing keys filled from |
897 | 913 |
the cluster defaults |
898 | 914 |
|
899 | 915 |
""" |
916 |
if skip_globals: |
|
917 |
skip_keys = constants.HVC_GLOBALS |
|
918 |
else: |
|
919 |
skip_keys = [] |
|
900 | 920 |
return FillDict(self.hvparams.get(instance.hypervisor, {}), |
901 |
instance.hvparams)
|
|
921 |
instance.hvparams, skip_keys=skip_keys)
|
|
902 | 922 |
|
903 | 923 |
def FillBE(self, instance): |
904 | 924 |
"""Fill an instance's beparams dict. |
... | ... | |
911 | 931 |
|
912 | 932 |
""" |
913 | 933 |
return FillDict(self.beparams.get(constants.PP_DEFAULT, {}), |
914 |
instance.beparams)
|
|
934 |
instance.beparams) |
|
915 | 935 |
|
916 | 936 |
|
917 | 937 |
class BlockDevStatus(ConfigObject): |
Also available in: Unified diff