Revision 5bf7b5cf
b/lib/objects.py | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import ConfigParser |
31 | 31 |
import re |
32 |
import copy |
|
32 | 33 |
from cStringIO import StringIO |
33 | 34 |
|
34 | 35 |
from ganeti import errors |
... | ... | |
504 | 505 |
"primary_node", |
505 | 506 |
"os", |
506 | 507 |
"hypervisor", |
508 |
"hvparams", |
|
509 |
"beparams", |
|
507 | 510 |
"status", |
508 | 511 |
"memory", |
509 | 512 |
"vcpus", |
... | ... | |
703 | 706 |
"cluster_name", |
704 | 707 |
"file_storage_dir", |
705 | 708 |
"enabled_hypervisors", |
709 |
"hvparams", |
|
710 |
"beparams", |
|
706 | 711 |
] |
707 | 712 |
|
708 | 713 |
def ToDict(self): |
... | ... | |
723 | 728 |
obj.tcpudp_port_pool = set(obj.tcpudp_port_pool) |
724 | 729 |
return obj |
725 | 730 |
|
731 |
@staticmethod |
|
732 |
def FillDict(defaults_dict, custom_dict): |
|
733 |
"""Basic function to apply settings on top a default dict. |
|
734 |
|
|
735 |
@type defaults_dict: dict |
|
736 |
@param defaults_dict: dictionary holding the default values |
|
737 |
@type custom_dict: dict |
|
738 |
@param custom_dict: dictionary holding customized value |
|
739 |
@rtype: dict |
|
740 |
@return: dict with the 'full' values |
|
741 |
|
|
742 |
""" |
|
743 |
ret_dict = copy.deepcopy(defaults_dict) |
|
744 |
ret_dict.update(custom_dict) |
|
745 |
return ret_dict |
|
746 |
|
|
747 |
def FillHV(self, instance): |
|
748 |
"""Fill an instance's hvparams dict. |
|
749 |
|
|
750 |
@type instance: object |
|
751 |
@param instance: the instance parameter to fill |
|
752 |
@rtype: dict |
|
753 |
@return: a copy of the instance's hvparams with missing keys filled from |
|
754 |
the cluster defaults |
|
755 |
|
|
756 |
""" |
|
757 |
return self.FillDict(self.hvparams.get(instance.hypervisor, {}), |
|
758 |
instance.hvparams) |
|
759 |
|
|
760 |
def FillBE(self, instance): |
|
761 |
"""Fill an instance's beparams dict. |
|
762 |
|
|
763 |
@type instance: object |
|
764 |
@param instance: the instance parameter to fill |
|
765 |
@rtype: dict |
|
766 |
@return: a copy of the instance's beparams with missing keys filled from |
|
767 |
the cluster defaults |
|
768 |
|
|
769 |
""" |
|
770 |
return self.FillDict(self.beparams.get(constants.BEGR_DEFAULT, {}), |
|
771 |
instance.beparams) |
|
772 |
|
|
726 | 773 |
|
727 | 774 |
class SerializableConfigParser(ConfigParser.SafeConfigParser): |
728 | 775 |
"""Simple wrapper over ConfigParse that allows serialization. |
Also available in: Unified diff