from ganeti import uidpool
from ganeti import netutils
from ganeti import runtime
+from ganeti import pathutils
_config_lock = locking.SharedLock("ConfigWriter")
self._config_data = None
self._offline = offline
if cfg_file is None:
- self._cfg_file = constants.CLUSTER_CONF_FILE
+ self._cfg_file = pathutils.CLUSTER_CONF_FILE
else:
self._cfg_file = cfg_file
self._getents = _getents
"""Check if the cluster is configured.
"""
- return os.path.exists(constants.CLUSTER_CONF_FILE)
+ return os.path.exists(pathutils.CLUSTER_CONF_FILE)
def _GenerateOneMAC(self):
"""Generate one mac address
return self._config_data.cluster.FillND(node, nodegroup)
@locking.ssynchronized(_config_lock, shared=1)
+ def GetInstanceDiskParams(self, instance):
+ """Get the disk params populated with inherit chain.
+
+ @type instance: L{objects.Instance}
+ @param instance: The instance we want to know the params for
+ @return: A dict with the filled in disk params
+
+ """
+ node = self._UnlockedGetNodeInfo(instance.primary_node)
+ nodegroup = self._UnlockedGetNodeGroup(node.group)
+ return self._UnlockedGetGroupDiskParams(nodegroup)
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetGroupDiskParams(self, group):
+ """Get the disk params populated with inherit chain.
+
+ @type group: L{objects.NodeGroup}
+ @param group: The group we want to know the params for
+ @return: A dict with the filled in disk params
+
+ """
+ return self._UnlockedGetGroupDiskParams(group)
+
+ def _UnlockedGetGroupDiskParams(self, group):
+ """Get the disk params populated with inherit chain down to node-group.
+
+ @type group: L{objects.NodeGroup}
+ @param group: The group we want to know the params for
+ @return: A dict with the filled in disk params
+
+ """
+ return self._config_data.cluster.SimpleFillDP(group.diskparams)
+
+ @locking.ssynchronized(_config_lock, shared=1)
def GenerateMAC(self, ec_id):
"""Generate a MAC for an instance.
except errors.ConfigurationError, err:
result.append("%s has invalid nicparams: %s" % (owner, err))
- def _helper_ipolicy(owner, params):
+ def _helper_ipolicy(owner, params, check_std):
try:
- objects.InstancePolicy.CheckParameterSyntax(params)
+ objects.InstancePolicy.CheckParameterSyntax(params, check_std)
except errors.ConfigurationError, err:
result.append("%s has invalid instance policy: %s" % (owner, err))
_helper_nic("cluster", cluster.SimpleFillNIC({}))
_helper("cluster", "ndparams", cluster.SimpleFillND({}),
constants.NDS_PARAMETER_TYPES)
- _helper_ipolicy("cluster", cluster.SimpleFillIPolicy({}))
+ _helper_ipolicy("cluster", cluster.SimpleFillIPolicy({}), True)
_helper_ispecs("cluster", cluster.SimpleFillIPolicy({}))
# per-instance checks
else:
nodegroups_names.add(nodegroup.name)
group_name = "group %s" % nodegroup.name
- _helper_ipolicy(group_name, cluster.SimpleFillIPolicy(nodegroup.ipolicy))
+ _helper_ipolicy(group_name, cluster.SimpleFillIPolicy(nodegroup.ipolicy),
+ False)
_helper_ispecs(group_name, cluster.SimpleFillIPolicy(nodegroup.ipolicy))
if nodegroup.ndparams:
_helper(group_name, "ndparams",
def AddTcpUdpPort(self, port):
"""Adds a new port to the available port pool.
+ @warning: this method does not "flush" the configuration (via
+ L{_WriteConfig}); callers should do that themselves once the
+ configuration is stable
+
"""
if not isinstance(port, int):
raise errors.ProgrammerError("Invalid type passed for port")
self._config_data.cluster.tcpudp_port_pool.add(port)
- self._WriteConfig()
@locking.ssynchronized(_config_lock, shared=1)
def GetPortList(self):
"""
cluster = self._config_data.cluster
- result = objects.MasterNetworkParameters(name=cluster.master_node,
- ip=cluster.master_ip,
- netmask=cluster.master_netmask,
- netdev=cluster.master_netdev,
+ result = objects.MasterNetworkParameters(
+ name=cluster.master_node, ip=cluster.master_ip,
+ netmask=cluster.master_netmask, netdev=cluster.master_netdev,
ip_family=cluster.primary_ip_family)
return result
if target is None:
if len(self._config_data.nodegroups) != 1:
raise errors.OpPrereqError("More than one node group exists. Target"
- " group must be specified explicitely.")
+ " group must be specified explicitly.")
else:
return self._config_data.nodegroups.keys()[0]
if target in self._config_data.nodegroups:
for member_name in
self._UnlockedGetNodeGroup(ngfn(node_name)).members)
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetMultiNodeGroupInfo(self, group_uuids):
+ """Get the configuration of multiple node groups.
+
+ @param group_uuids: List of node group UUIDs
+ @rtype: list
+ @return: List of tuples of (group_uuid, group_info)
+
+ """
+ return [(uuid, self._UnlockedGetNodeGroup(uuid)) for uuid in group_uuids]
+
@locking.ssynchronized(_config_lock)
def AddInstance(self, instance, ec_id):
"""Add an instance to the config.