Revision 43905206

b/lib/cmdlib.py
217 217
    """
218 218
    return lu_result
219 219

  
220
  def _ExpandAndLockInstance(self):
221
    """Helper function to expand and lock an instance.
222

  
223
    Many LUs that work on an instance take its name in self.op.instance_name
224
    and need to expand it and then declare the expanded name for locking. This
225
    function does it, and then updates self.op.instance_name to the expanded
226
    name. It also initializes needed_locks as a dict, if this hasn't been done
227
    before.
228

  
229
    """
230
    if self.needed_locks is None:
231
      self.needed_locks = {}
232
    else:
233
      assert locking.LEVEL_INSTANCE not in self.needed_locks, \
234
        "_ExpandAndLockInstance called with instance-level locks set"
235
    expanded_name = self.cfg.ExpandInstanceName(self.op.instance_name)
236
    if expanded_name is None:
237
      raise errors.OpPrereqError("Instance '%s' not known" %
238
                                  self.op.instance_name)
239
    self.needed_locks[locking.LEVEL_INSTANCE] = expanded_name
240
    self.op.instance_name = expanded_name
241

  
220 242

  
221 243
class NoHooksLU(LogicalUnit):
222 244
  """Simple LU which runs no hooks.

Also available in: Unified diff