From a82ce292c8b8375729b88c7d540d1325ab9df676 Mon Sep 17 00:00:00 2001 From: Guido Trotter Date: Mon, 8 Sep 2008 13:43:43 +0000 Subject: [PATCH] Add primary_only flag to _LockInstancesNodes As the name says when the flag is on (the default is off) only the primary nodes are locked, as opposed to all of them. Reviewed-by: iustinp --- lib/cmdlib.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index f5b2e78..9526a06 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -261,7 +261,7 @@ class LogicalUnit(object): self.needed_locks[locking.LEVEL_INSTANCE] = expanded_name self.op.instance_name = expanded_name - def _LockInstancesNodes(self): + def _LockInstancesNodes(self, primary_only=False): """Helper function to declare instances' nodes for locking. This function should be called after locking one or more instances to lock @@ -280,6 +280,9 @@ class LogicalUnit(object): if level == locking.LEVEL_NODE: self._LockInstancesNodes() + @type primary_only: boolean + @param primary_only: only lock primary nodes of locked instances + """ assert locking.LEVEL_NODE in self.recalculate_locks, \ "_LockInstancesNodes helper function called with no nodes to recalculate" @@ -293,7 +296,8 @@ class LogicalUnit(object): for instance_name in self.acquired_locks[locking.LEVEL_INSTANCE]: instance = self.context.cfg.GetInstanceInfo(instance_name) wanted_nodes.append(instance.primary_node) - wanted_nodes.extend(instance.secondary_nodes) + if not primary_only: + wanted_nodes.extend(instance.secondary_nodes) self.needed_locks[locking.LEVEL_NODE] = wanted_nodes del self.recalculate_locks[locking.LEVEL_NODE] -- 1.7.10.4