+ def RemoveNodeGroup(self, group_uuid):
+ """Remove a node group from the configuration.
+
+ @type group_uuid: string
+ @param group_uuid: the UUID of the node group to remove
+
+ """
+ logging.info("Removing node group %s from configuration", group_uuid)
+
+ if group_uuid not in self._config_data.nodegroups:
+ raise errors.ConfigurationError("Unknown node group '%s'" % group_uuid)
+
+ assert len(self._config_data.nodegroups) != 1, \
+ "Group '%s' is the only group, cannot be removed" % group_uuid
+
+ del self._config_data.nodegroups[group_uuid]
+ self._config_data.cluster.serial_no += 1
+ self._WriteConfig()
+
+ def _UnlockedLookupNodeGroup(self, target):
+ """Lookup a node group's UUID.
+
+ @type target: string or None
+ @param target: group name or UUID or None to look for the default
+ @rtype: string
+ @return: nodegroup UUID
+ @raises errors.OpPrereqError: when the target group cannot be found
+
+ """
+ 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.")
+ else:
+ return self._config_data.nodegroups.keys()[0]
+ if target in self._config_data.nodegroups:
+ return target
+ for nodegroup in self._config_data.nodegroups.values():
+ if nodegroup.name == target:
+ return nodegroup.uuid
+ raise errors.OpPrereqError("Node group '%s' not found" % target,
+ errors.ECODE_NOENT)
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def LookupNodeGroup(self, target):
+ """Lookup a node group's UUID.
+
+ This function is just a wrapper over L{_UnlockedLookupNodeGroup}.
+
+ @type target: string or None
+ @param target: group name or UUID or None to look for the default
+ @rtype: string
+ @return: nodegroup UUID
+
+ """
+ return self._UnlockedLookupNodeGroup(target)
+
+ def _UnlockedGetNodeGroup(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 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
+
+ """
+ return self._UnlockedGetNodeGroup(uuid)
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GetAllNodeGroupsInfo(self):
+ """Get the configuration of all node groups.
+
+ """
+ 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, shared=1)
+ def GetNodeGroupMembersByNodes(self, nodes):
+ """Get nodes which are member in the same nodegroups as the given nodes.
+
+ """
+ ngfn = lambda node_name: self._UnlockedGetNodeInfo(node_name).group
+ return frozenset(member_name
+ for node_name in nodes
+ for member_name in
+ self._UnlockedGetNodeGroup(ngfn(node_name)).members)
+
+ @locking.ssynchronized(_config_lock)
+ def AddInstance(self, instance, ec_id):