import errno
import logging
+from ganeti import compat
from ganeti import errors
from ganeti import constants
from ganeti import utils
SSCONF_LOCK_TIMEOUT = 10
#: Valid ssconf keys
-_VALID_KEYS = frozenset([
+_VALID_KEYS = compat.UniqueFrozenset([
constants.SS_CLUSTER_NAME,
constants.SS_CLUSTER_TAGS,
constants.SS_FILE_STORAGE_DIR,
constants.SS_UID_POOL,
constants.SS_NODEGROUPS,
constants.SS_NETWORKS,
+ constants.SS_HVPARAMS_XEN_PVM,
+ constants.SS_HVPARAMS_XEN_FAKE,
+ constants.SS_HVPARAMS_XEN_HVM,
+ constants.SS_HVPARAMS_XEN_KVM,
+ constants.SS_HVPARAMS_XEN_CHROOT,
+ constants.SS_HVPARAMS_XEN_LXC,
])
#: Maximum size for ssconf files
raise errors.ConfigurationError("Can't read ssconf file %s: %s" %
(filename, str(err)))
+ def ReadAll(self):
+ """Reads all keys and returns their values.
+
+ @rtype: dict
+ @return: Dictionary, ssconf key as key, value as value
+
+ """
+ result = []
+
+ for key in _VALID_KEYS:
+ try:
+ value = self._ReadFile(key)
+ except errors.ConfigurationError:
+ # Ignore non-existing files
+ pass
+ else:
+ result.append((key, value))
+
+ return dict(result)
+
def WriteFiles(self, values, dry_run=False):
"""Writes ssconf files used by external scripts.
nl = data.splitlines(False)
return nl
+ def GetHvparamsForHypervisor(self, hvname):
+ """Return the hypervisor parameters of the given hypervisor.
+
+ @type hvname: string
+ @param hvname: name of the hypervisor, must be in C{constants.HYPER_TYPES}
+ @rtype: dict of strings
+ @returns: dictionary with hypervisor parameters
+
+ """
+ data = self._ReadFile(constants.SS_HVPARAMS_PREF + hvname)
+ lines = data.splitlines(False)
+ hvparams = {}
+ for line in lines:
+ (key, value) = line.split("=")
+ hvparams[key] = value
+ return hvparams
+
+ def GetHvparams(self):
+ """Return the hypervisor parameters of all hypervisors.
+
+ @rtype: dict of dict of strings
+ @returns: dictionary mapping hypervisor names to hvparams
+
+ """
+ all_hvparams = {}
+ for hv in constants.HYPER_TYPES:
+ all_hvparams[hv] = self.GetHvparamsForHypervisor(hv)
+ return all_hvparams
+
def GetMaintainNodeHealth(self):
"""Return the value of the maintain_node_health option.