self._ec_reserved = {}
def Reserved(self, resource):
- for holder_reserved in self._ec_reserved.items():
+ for holder_reserved in self._ec_reserved.values():
if resource in holder_reserved:
return True
return False
def Reserve(self, ec_id, resource):
if self.Reserved(resource):
- raise errors.ReservationError("Duplicate reservation for resource: %s." %
- (resource))
+ raise errors.ReservationError("Duplicate reservation for resource '%s'"
+ % str(resource))
if ec_id not in self._ec_reserved:
self._ec_reserved[ec_id] = set([resource])
else:
if [node.master_candidate, node.drained, node.offline].count(True) > 1:
result.append("Node %s state is invalid: master_candidate=%s,"
" drain=%s, offline=%s" %
- (node.name, node.master_candidate, node.drain,
+ (node.name, node.master_candidate, node.drained,
node.offline))
# nodegroups checks
@locking.ssynchronized(_config_lock, shared=1)
def LookupNodeGroup(self, target):
- """Lookup a node group.
+ """Lookup a node group's UUID.
@type target: string or None
- @param target: group name or uuid or None to look for the default
+ @param target: group name or UUID or None to look for the default
@rtype: string
- @return: nodegroup uuid
+ @return: nodegroup UUID
@raises errors.OpPrereqError: when the target group cannot be found
"""
for nodegroup in self._config_data.nodegroups.values():
if nodegroup.name == target:
return nodegroup.uuid
- raise errors.OpPrereqError("Nodegroup '%s' not found", target)
+ raise errors.OpPrereqError("Nodegroup '%s' not found" % target)
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetNodeGroup(self, uuid):
+ """Lookup a node group.
+
+ @type uuid: string
+ @param uuid: group UUID
+ @rtype: L{objects.NodeGroup} or None
+ @return: nodegroup object, or None if not found
+
+ """
+ if uuid not in self._config_data.nodegroups:
+ return None
+
+ return self._config_data.nodegroups[uuid]
@locking.ssynchronized(_config_lock, shared=1)
def GetAllNodeGroupsInfo(self):
"""
return dict(self._config_data.nodegroups)
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetNodeGroupList(self):
+ """Get a list of node groups.
+
+ """
+ return self._config_data.nodegroups.keys()
+
@locking.ssynchronized(_config_lock)
def AddInstance(self, instance, ec_id):
"""Add an instance to the config.
if disk.dev_type == constants.LD_FILE:
# rename the file paths in logical and physical id
file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1]))
+ disk_fname = "disk%s" % disk.iv_name.split("/")[1]
disk.physical_id = disk.logical_id = (disk.logical_id[0],
utils.PathJoin(file_storage_dir,
inst.name,
- disk.iv_name))
+ disk_fname))
+
+ # Force update of ssconf files
+ self._config_data.cluster.serial_no += 1
self._config_data.instances[inst.name] = inst
self._WriteConfig()
"""
return self._UnlockedGetNodeInfo(node_name)
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetNodeInstances(self, node_name):
+ """Get the instances of a node, as stored in the config.
+
+ @param node_name: the node name, e.g. I{node1.example.com}
+
+ @rtype: (list, list)
+ @return: a tuple with two lists: the primary and the secondary instances
+
+ """
+ pri = []
+ sec = []
+ for inst in self._config_data.instances.values():
+ if inst.primary_node == node_name:
+ pri.append(inst.name)
+ if node_name in inst.secondary_nodes:
+ sec.append(inst.name)
+ return (pri, sec)
+
def _UnlockedGetNodeList(self):
"""Return the list of nodes which are in the configuration.
return self._UnlockedGetOnlineNodeList()
@locking.ssynchronized(_config_lock, shared=1)
+ def GetNonVmCapableNodeList(self):
+ """Return the list of nodes which are not vm capable.
+
+ """
+ all_nodes = [self._UnlockedGetNodeInfo(node)
+ for node in self._UnlockedGetNodeList()]
+ return [node.name for node in all_nodes if not node.vm_capable]
+
+ @locking.ssynchronized(_config_lock, shared=1)
def GetAllNodesInfo(self):
"""Get the configuration of all nodes.
for node in self._config_data.nodes.values():
if exceptions and node.name in exceptions:
continue
- if not (node.offline or node.drained):
+ if not (node.offline or node.drained) and node.master_capable:
mc_max += 1
if node.master_candidate:
mc_now += 1
break
node = self._config_data.nodes[name]
if (node.master_candidate or node.offline or node.drained or
- node.name in exceptions):
+ node.name in exceptions or not node.master_capable):
continue
mod_list.append(node)
node.master_candidate = True