diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 37c45d06647775ee881b2ded5b4ad1c4f615402b..dee811d35fbbb158ab8c08a8f170e6396f0998c8 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2580,6 +2580,16 @@ class LUFailoverInstance(LogicalUnit): HPATH = "instance-failover" HTYPE = constants.HTYPE_INSTANCE _OP_REQP = ["instance_name", "ignore_consistency"] + REQ_BGL = False + + def ExpandNames(self): + self._ExpandAndLockInstance() + self.needed_locks[locking.LEVEL_NODE] = [] + self.recalculate_locks[locking.LEVEL_NODE] = 'replace' + + def DeclareLocks(self, level): + if level == locking.LEVEL_NODE: + self._LockInstancesNodes() def BuildHooksEnv(self): """Build hooks env. @@ -2600,11 +2610,9 @@ class LUFailoverInstance(LogicalUnit): This checks that the instance is in the cluster. """ - instance = self.cfg.GetInstanceInfo( - self.cfg.ExpandInstanceName(self.op.instance_name)) - if instance is None: - raise errors.OpPrereqError("Instance '%s' not known" % - self.op.instance_name) + self.instance = instance = self.cfg.GetInstanceInfo(self.op.instance_name) + assert self.instance is not None, \ + "Cannot retrieve locked instance %s" % self.op.instance_name if instance.disk_template not in constants.DTS_NET_MIRROR: raise errors.OpPrereqError("Instance's disk layout is not" @@ -2627,8 +2635,6 @@ class LUFailoverInstance(LogicalUnit): " exist on destination node '%s'" % (brlist, target_node)) - self.instance = instance - def Exec(self, feedback_fn): """Failover an instance.