From: Michael Hanselmann Date: Fri, 5 Aug 2011 11:05:38 +0000 (+0200) Subject: cmdlib: Factorize checking node groups' instances X-Git-Tag: v2.5.0beta1~46 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/b9ff3e152eadecb50d3c5f3737d4e9c0386babe3 cmdlib: Factorize checking node groups' instances Signed-off-by: Michael Hanselmann Reviewed-by: Iustin Pop --- diff --git a/lib/cmdlib.py b/lib/cmdlib.py index d6bf26e..592dbf3 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -583,6 +583,30 @@ def _CheckInstanceNodeGroups(cfg, instance_name, owned_groups): return inst_groups +def _CheckNodeGroupInstances(cfg, group_uuid, owned_instances): + """Checks if the instances in a node group are still correct. + + @type cfg: L{config.ConfigWriter} + @param cfg: The cluster configuration + @type group_uuid: string + @param group_uuid: Node group UUID + @type owned_instances: set or frozenset + @param owned_instances: List of currently owned instances + + """ + wanted_instances = cfg.GetNodeGroupInstances(group_uuid) + if owned_instances != wanted_instances: + raise errors.OpPrereqError("Instances in node group '%s' changed since" + " locks were acquired, wanted '%s', have '%s';" + " retry the operation" % + (group_uuid, + utils.CommaJoin(wanted_instances), + utils.CommaJoin(owned_instances)), + errors.ECODE_STATE) + + return wanted_instances + + def _SupportsOob(cfg, node): """Tells if node supports OOB. @@ -2997,15 +3021,7 @@ class LUGroupVerifyDisks(NoHooksLU): assert self.group_uuid in owned_groups # Check if locked instances are still correct - wanted_instances = self.cfg.GetNodeGroupInstances(self.group_uuid) - if owned_instances != wanted_instances: - raise errors.OpPrereqError("Instances in node group %s changed since" - " locks were acquired, wanted %s, have %s;" - " retry the operation" % - (self.op.group_name, - utils.CommaJoin(wanted_instances), - utils.CommaJoin(owned_instances)), - errors.ECODE_STATE) + _CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances) # Get instance information self.instances = dict(self.cfg.GetMultiInstanceInfo(owned_instances)) @@ -12292,15 +12308,7 @@ class LUGroupEvacuate(LogicalUnit): assert self.group_uuid in owned_groups # Check if locked instances are still correct - wanted_instances = self.cfg.GetNodeGroupInstances(self.group_uuid) - if owned_instances != wanted_instances: - raise errors.OpPrereqError("Instances in node group to be evacuated (%s)" - " changed since locks were acquired, wanted" - " %s, have %s; retry the operation" % - (self.group_uuid, - utils.CommaJoin(wanted_instances), - utils.CommaJoin(owned_instances)), - errors.ECODE_STATE) + _CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances) # Get instance information self.instances = dict(self.cfg.GetMultiInstanceInfo(owned_instances))