From eaa98a048505508d7943726795579b760daab2cd Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Mon, 13 Sep 2010 15:02:24 +0100 Subject: [PATCH] config.LookupNodeGroup This function allows a node group to be looked up by name or uuid. If no nodegroup is specified and only one exists, that one is returned. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/config.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/config.py b/lib/config.py index 93f591304..1383b773f 100644 --- a/lib/config.py +++ b/lib/config.py @@ -845,6 +845,30 @@ class ConfigWriter: """ return self._config_data.cluster.primary_ip_family + @locking.ssynchronized(_config_lock, shared=1) + def LookupNodeGroup(self, target): + """Lookup a node group. + + @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 nodegroup 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("Nodegroup '%s' not found", target) + @locking.ssynchronized(_config_lock) def AddInstance(self, instance, ec_id): """Add an instance to the config. -- GitLab