return utils.MatchNameComponent(short_name, names, case_sensitive=False)
+def _CheckInstanceDiskIvNames(disks):
+ """Checks if instance's disks' C{iv_name} attributes are in order.
+
+ @type disks: list of L{objects.Disk}
+ @param disks: List of disks
+ @rtype: list of tuples; (int, string, string)
+ @return: List of wrongly named disks, each tuple contains disk index,
+ expected and actual name
+
+ """
+ result = []
+
+ for (idx, disk) in enumerate(disks):
+ exp_iv_name = "disk/%s" % idx
+ if disk.iv_name != exp_iv_name:
+ result.append((idx, exp_iv_name, disk.iv_name))
+
+ return result
+
+
class ConfigWriter:
"""The interface to the cluster configuration.
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
(instance.name, idx, msg) for msg in disk.Verify()])
result.extend(self._CheckDiskIDs(disk, seen_lids, seen_pids))
+ wrong_names = _CheckInstanceDiskIvNames(instance.disks)
+ if wrong_names:
+ tmp = "; ".join(("name of disk %s should be '%s', but is '%s'" %
+ (idx, exp_name, actual_name))
+ for (idx, exp_name, actual_name) in wrong_names)
+
+ result.append("Instance '%s' has wrongly named disks: %s" %
+ (instance.name, tmp))
+
# cluster-wide pool of free ports
for free_port in cluster.tcpudp_port_pool:
if free_port not in ports:
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):
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.
# Make sure the configuration has the right version
_ValidateConfig(data)
- if (not hasattr(data, 'cluster') or
- not hasattr(data.cluster, 'rsahostkeypub')):
+ if (not hasattr(data, "cluster") or
+ not hasattr(data.cluster, "rsahostkeypub")):
raise errors.ConfigurationError("Incomplete configuration"
" (missing cluster.rsahostkeypub)")