#
#
-# Copyright (C) 2006, 2007 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""
+# pylint: disable-msg=R0904
+# R0904: Too many public methods
+
import os
import random
import logging
from ganeti import rpc
from ganeti import objects
from ganeti import serializer
+from ganeti import uidpool
+from ganeti import netutils
+from ganeti import runtime
-_config_lock = locking.SharedLock()
+_config_lock = locking.SharedLock("ConfigWriter")
# job id used for resource management at config upgrade time
_UPGRADE_CONFIG_JID = "jid-cfg-upgrade"
@ivar _all_rms: a list of all temporary reservation managers
"""
- def __init__(self, cfg_file=None, offline=False):
+ def __init__(self, cfg_file=None, offline=False, _getents=runtime.GetEnts):
self.write_count = 0
self._lock = _config_lock
self._config_data = None
self._cfg_file = constants.CLUSTER_CONF_FILE
else:
self._cfg_file = cfg_file
+ self._getents = _getents
self._temporary_ids = TemporaryReservationManager()
self._temporary_drbds = {}
self._temporary_macs = TemporaryReservationManager()
# _DistributeConfig, we compute it here once and reuse it; it's
# better to raise an error before starting to modify the config
# file than after it was modified
- self._my_hostname = utils.HostInfo().name
+ self._my_hostname = netutils.Hostname.GetSysName()
self._last_cluster_serial = -1
self._OpenConfig()
if invalid_hvs:
result.append("enabled hypervisors contains invalid entries: %s" %
invalid_hvs)
+ missing_hvp = (set(data.cluster.enabled_hypervisors) -
+ set(data.cluster.hvparams.keys()))
+ if missing_hvp:
+ result.append("hypervisor parameters missing for the enabled"
+ " hypervisor(s) %s" % utils.CommaJoin(missing_hvp))
if data.cluster.master_node not in data.nodes:
result.append("cluster has invalid primary node '%s'" %
"""
return self._config_data.cluster.rsahostkeypub
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetDefaultIAllocator(self):
+ """Get the default instance allocator for this cluster.
+
+ """
+ return self._config_data.cluster.default_iallocator
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetPrimaryIPFamily(self):
+ """Get cluster primary ip family.
+
+ @return: primary ip family
+
+ """
+ return self._config_data.cluster.primary_ip_family
+
@locking.ssynchronized(_config_lock)
def AddInstance(self, instance, ec_id):
"""Add an instance to the config.
This is because some data elements need uniqueness across the
whole configuration, etc.
- @warning: this function will call L{_WriteConfig()}, so it needs
- to either be called with the lock held or from a safe place
- (the constructor)
+ @warning: this function will call L{_WriteConfig()}, but also
+ L{DropECReservations} so it needs to be called only from a
+ "safe" place (the constructor). If one wanted to call it with
+ the lock held, a DropECReservationUnlocked would need to be
+ created first, to avoid causing deadlock.
"""
modified = False
self._BumpSerialNo()
txt = serializer.Dump(self._config_data.ToDict())
- utils.WriteFile(destination, data=txt)
+ getents = self._getents()
+ utils.WriteFile(destination, data=txt, gid=getents.confd_gid, mode=0640)
self.write_count += 1
hypervisor_list = fn(cluster.enabled_hypervisors)
+ uid_pool = uidpool.FormatUidPool(cluster.uid_pool, separator="\n")
+
return {
constants.SS_CLUSTER_NAME: cluster.cluster_name,
constants.SS_CLUSTER_TAGS: cluster_tags,
constants.SS_NODE_SECONDARY_IPS: node_snd_ips_data,
constants.SS_OFFLINE_NODES: off_data,
constants.SS_ONLINE_NODES: on_data,
+ constants.SS_PRIMARY_IP_FAMILY: str(cluster.primary_ip_family),
constants.SS_INSTANCE_LIST: instance_data,
constants.SS_RELEASE_VERSION: constants.RELEASE_VERSION,
constants.SS_HYPERVISOR_LIST: hypervisor_list,
constants.SS_MAINTAIN_NODE_HEALTH: str(cluster.maintain_node_health),
+ constants.SS_UID_POOL: uid_pool,
}
@locking.ssynchronized(_config_lock, shared=1)
+ def GetSsconfValues(self):
+ """Wrapper using lock around _UnlockedGetSsconf().
+
+ """
+ return self._UnlockedGetSsconfValues()
+
+ @locking.ssynchronized(_config_lock, shared=1)
def GetVGName(self):
"""Return the volume group name.
self._WriteConfig()
@locking.ssynchronized(_config_lock, shared=1)
+ def GetDRBDHelper(self):
+ """Return DRBD usermode helper.
+
+ """
+ return self._config_data.cluster.drbd_usermode_helper
+
+ @locking.ssynchronized(_config_lock)
+ def SetDRBDHelper(self, drbd_helper):
+ """Set DRBD usermode helper.
+
+ """
+ self._config_data.cluster.drbd_usermode_helper = drbd_helper
+ self._config_data.cluster.serial_no += 1
+ self._WriteConfig()
+
+ @locking.ssynchronized(_config_lock, shared=1)
def GetMACPrefix(self):
"""Return the mac prefix.
"""
return self._config_data.cluster
+ @locking.ssynchronized(_config_lock, shared=1)
+ def HasAnyDiskOfType(self, dev_type):
+ """Check if in there is at disk of the given type in the configuration.
+
+ """
+ return self._config_data.HasAnyDiskOfType(dev_type)
+
@locking.ssynchronized(_config_lock)
def Update(self, target, feedback_fn):
"""Notify function to be called after updates.