Revision a987fa48 lib/cmdlib.py

b/lib/cmdlib.py
4145 4145

  
4146 4146
  """
4147 4147
  _OP_REQP = ["instances"]
4148
  REQ_BGL = False
4149
  def ExpandNames(self):
4150
    self.needed_locks = {}
4151
    self.share_locks = dict(((i, 1) for i in locking.LEVELS))
4152

  
4153
    if not isinstance(self.op.instances, list):
4154
      raise errors.OpPrereqError("Invalid argument type 'instances'")
4155

  
4156
    if self.op.instances:
4157
      self.wanted_names = []
4158
      for name in self.op.instances:
4159
        full_name = self.cfg.ExpandInstanceName(name)
4160
        if full_name is None:
4161
          raise errors.OpPrereqError("Instance '%s' not known" %
4162
                                     self.op.instance_name)
4163
        self.wanted_names.append(full_name)
4164
      self.needed_locks[locking.LEVEL_INSTANCE] = self.wanted_names
4165
    else:
4166
      self.wanted_names = None
4167
      self.needed_locks[locking.LEVEL_INSTANCE] = locking.ALL_SET
4168

  
4169
    self.needed_locks[locking.LEVEL_NODE] = []
4170
    self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
4171

  
4172
  def DeclareLocks(self, level):
4173
    if level == locking.LEVEL_NODE:
4174
      self._LockInstancesNodes()
4148 4175

  
4149 4176
  def CheckPrereq(self):
4150 4177
    """Check prerequisites.
......
4152 4179
    This only checks the optional instance list against the existing names.
4153 4180

  
4154 4181
    """
4155
    if not isinstance(self.op.instances, list):
4156
      raise errors.OpPrereqError("Invalid argument type 'instances'")
4157
    if self.op.instances:
4158
      self.wanted_instances = []
4159
      names = self.op.instances
4160
      for name in names:
4161
        instance = self.cfg.GetInstanceInfo(self.cfg.ExpandInstanceName(name))
4162
        if instance is None:
4163
          raise errors.OpPrereqError("No such instance name '%s'" % name)
4164
        self.wanted_instances.append(instance)
4165
    else:
4166
      self.wanted_instances = [self.cfg.GetInstanceInfo(name) for name
4167
                               in self.cfg.GetInstanceList()]
4168
    return
4182
    if self.wanted_names is None:
4183
      self.wanted_names = self.acquired_locks[locking.LEVEL_INSTANCE]
4169 4184

  
4185
    self.wanted_instances = [self.cfg.GetInstanceInfo(name) for name
4186
                             in self.wanted_names]
4187
    return
4170 4188

  
4171 4189
  def _ComputeDiskStatus(self, instance, snode, dev):
4172 4190
    """Compute block device status.

Also available in: Unified diff